Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void main()
  4. {
  5. int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
  6. float avg_wt,avg_tat;
  7. printf("Enter number of process:");
  8. scanf("%d",&n);
  9.  
  10. printf("\nEnter Burst Time:\n");
  11. for(i=0; i<n; i++)
  12. {
  13. printf("p%d:",i+1);
  14. scanf("%d",&bt[i]);
  15. p[i]=i+1;
  16. }
  17.  
  18. for(i=0; i<n; i++)
  19. {
  20. pos=i;
  21. for(j=i+1; j<n; j++)
  22. {
  23. if(bt[j]<bt[pos])
  24. pos=j;
  25. }
  26.  
  27. temp=bt[i];
  28. bt[i]=bt[pos];
  29. bt[pos]=temp;
  30.  
  31. temp=p[i];
  32. p[i]=p[pos];
  33. p[pos]=temp;
  34. }
  35.  
  36. wt[0]=0;
  37.  
  38. for(i=1; i<n; i++)
  39. {
  40. wt[i]=0;
  41. for(j=0; j<i; j++)
  42. wt[i]+=bt[j];
  43.  
  44. total+=wt[i];
  45. }
  46.  
  47. avg_wt=(float)total/n;
  48. total=0;
  49.  
  50. printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
  51. for(i=0; i<n; i++)
  52. {
  53. tat[i]=bt[i]+wt[i];
  54. total+=tat[i];
  55. printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
  56. }
  57.  
  58. avg_tat=(float)total/n;
  59. printf("\n\nAverage Waiting Time=%f",avg_wt);
  60. printf("\nAverage Turnaround Time=%f\n",avg_tat);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement