Guest User

Untitled

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