Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 6
  8. 7
  9. 8
  10. 9
  11. 10
  12. 11
  13. 12
  14. 13
  15. 14
  16. 15
  17. 16
  18. 17
  19. 18
  20. 19
  21. 20
  22. 21
  23. 22
  24. 23
  25. 24
  26. 25
  27. 26
  28. 27
  29. 28
  30. 29
  31. 30
  32. 31
  33. 32
  34. 33
  35. 34
  36. 35
  37. 36
  38. 37
  39. 38
  40. 39
  41. 40
  42. 41
  43. 42
  44. 43
  45. #include<stdio.h>
  46.  
  47. int main()
  48. {
  49. int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
  50. printf("Enter total number of processes(maximum 20):");
  51. scanf("%d",&n);
  52.  
  53. printf("\nEnter Process Burst Time\n");
  54. for(i=0;i<n;i++)
  55. {
  56. printf("P[%d]:",i+1);
  57. scanf("%d",&bt[i]);
  58. }
  59.  
  60. wt[0]=0; //waiting time for first process is 0
  61.  
  62. //calculating waiting time
  63. for(i=1;i<n;i++)
  64. {
  65. wt[i]=0;
  66. for(j=0;j<i;j++)
  67. wt[i]+=bt[j];
  68. }
  69.  
  70. printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
  71.  
  72. //calculating turnaround time
  73. for(i=0;i<n;i++)
  74. {
  75. tat[i]=bt[i]+wt[i];
  76. avwt+=wt[i];
  77. avtat+=tat[i];
  78. printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
  79. }
  80.  
  81. avwt/=i;
  82. avtat/=i;
  83. printf("\n\nAverage Waiting Time:%d",avwt);
  84. printf("\nAverage Turnaround Time:%d",avtat);
  85.  
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement