fork download
  1. #include <stdio.h>
  2. int main(){
  3. int p[10],at[10],bt[10],ct[10],tat[10],wt[10],i,j,temp=0,n;
  4. float awt=0,atat=0;
  5. printf("enter no of process:\n");
  6. scanf("%d",&n);
  7. printf("Enter processes:\n");
  8. for(i=0;i<n;i++){
  9. scanf("%d",&p[i]);
  10. }
  11. printf("Enter arrival time of each process:\n");
  12. for(i=0;i<n;i++){
  13. scanf("%d",&at[i]);
  14. }
  15. printf("Enter burst time for each processes:\n");
  16. for(i=0;i<n;i++){
  17. scanf("%d",&bt[i]);
  18. }
  19. for(i=0;i<n;i++){
  20. for(j=0;j<n-i-1;j++){
  21. if(at[j]>at[j+1]){
  22. temp=p[j+1];
  23. p[j+1]=p[j];
  24. p[j]=temp;
  25. temp=at[j+1];
  26. at[j+1]=at[j];
  27. at[j]=temp;
  28. temp=bt[j+1];
  29. bt[j+1]=bt[j];
  30. bt[j]=temp;
  31. }
  32. }
  33. }
  34. ct[0]=at[0]+bt[0];
  35. for(i=1;i<n;i++){
  36. temp=0;
  37. if(ct[i-1]<at[i]){
  38. temp=at[i]-ct[i-1];
  39. }
  40. ct[i]=bt[i]+ct[i-1]+temp;
  41. }
  42. printf("\n p\t AT\t BT\t CT\t TAT\t WT\t");
  43. for(i=0;i<n;i++){
  44. tat[i]=ct[i]-at[i];
  45. wt[i]=tat[i]-bt[i];
  46. atat+=tat[i];
  47. awt+=wt[i];
  48. }
  49. atat=atat/n;
  50. awt=awt/n;
  51. for(i=0;i<n;i++){
  52. printf("\n P%d\t %d\t %d\t %d\t %f\t %f",p[i],at[i],bt[i],ct[i],tat[i],wt[i]);
  53. }
  54. printf("avg tuen around time=%d",atat);
  55. printf("avg waiting time =%d",awt);
  56. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
1 2 3
24 3 3
stdout
enter no of process:
Enter processes:
Enter arrival time of each process:
Enter burst time for each processes:

 p	 AT	 BT	 CT	 TAT	 WT	
 P2	 3	 32767	 32770	 0.000000	 0.000000
 P3	 3	 1311375888	 1311408658	 0.000000	 0.000000
 P1	 24	 1311375872	 -1672182766	 0.000000	 0.000000avg tuen around time=1311408634avg waiting time =0