Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int bt[20],p[20],wt[20],i,j,n,total=0,pos,temp;
  6. float avg_wt;
  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. }
  45.  
  46. for(i=1;i<n;i++)
  47. {
  48. total+=wt[i];
  49. }
  50. avg_wt=(float)total/n;
  51.  
  52.  
  53. printf("\nProcess\t Burst Time \tWaiting Time");
  54. for(i=0;i<n;i++)
  55. {
  56. printf("\np%d\t\t %d\t\t %d",p[i],bt[i],wt[i]);
  57. }
  58.  
  59. printf("\n\nTotal Waiting Time=%d",total);
  60. printf("\n\nAverage Waiting Time=%f",avg_wt);
  61.  
  62. return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement