Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,n,p[10],min,k=1,btime=0;
  5. int bt[10],temp,j,at[10],wt[10],tt[10],ta=0,sum=0;
  6. float wavg=0,tavg=0,tsum=0,wsum=0;
  7. printf("\nEnter the No. of processes :");
  8. scanf("%d",&n);
  9.  
  10. for(i=0;i<n;i++)
  11. {
  12. printf("\tEnter the burst time of %d process :",i+1);
  13. scanf(" %d",&bt[i]);
  14. printf("\tEnter the arrival time of %d process :",i+1);
  15. scanf(" %d",&at[i]);
  16. p[i] = i+1;
  17. }
  18.  
  19. for(i=0;i<n;i++)
  20. {
  21. for(j=0;j<n;j++)
  22. {
  23. if(at[i]<at[j])
  24. {
  25. temp=p[j];
  26. p[j]=p[i];
  27. p[i]=temp;
  28.  
  29. temp=at[j];
  30. at[j]=at[i];
  31. at[i]=temp;
  32.  
  33. temp=bt[j];
  34. bt[j]=bt[i];
  35. bt[i]=temp;
  36. }
  37. }
  38. }
  39.  
  40. for(j=0;j<n;j++)
  41. {
  42. btime=btime+bt[j];
  43. min=bt[k];
  44. for(i=k;i<n;i++)
  45. {
  46. if (btime>=at[i] && bt[i]<min)
  47. {
  48. temp=p[k];
  49. p[k]=p[i];
  50. p[i]=temp;
  51.  
  52. temp=at[k];
  53. at[k]=at[i];
  54. at[i]=temp;
  55.  
  56. temp=bt[k];
  57. bt[k]=bt[i];
  58. bt[i]=temp;
  59. }
  60. }
  61. k++;
  62. }
  63.  
  64. wt[0]=0;
  65. for(i=1;i<n;i++)
  66. {
  67. sum=sum+bt[i-1];
  68. wt[i]=sum-at[i];
  69. wsum=wsum+wt[i];
  70. }
  71.  
  72. wavg=(wsum/n);
  73.  
  74. for(i=0;i<n;i++)
  75. {
  76. ta=ta+bt[i];
  77. tt[i]=ta-at[i];
  78. tsum=tsum+tt[i];
  79. }
  80.  
  81. tavg=(tsum/n);
  82.  
  83. printf("\n RESULT:-");
  84. printf("\nProcess\t Burst\t Arrival\t Waiting\t Turn-around" );
  85. for(i=0;i<n;i++)
  86. {
  87. printf("\n p%d\t %d\t %d\t\t %d\t\t\t%d",p[i],bt[i],at[i],wt[i],tt[i]);
  88. }
  89.  
  90. printf("\n\nAVERAGE WAITING TIME : %f",wavg);
  91. printf("\nAVERAGE TURN AROUND TIME : %f",tavg);
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement