al__nasim

fcfs with arrival time.cpp

Jan 14th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n,p,b[100], w=0,t,temp=0,arvTime[100];
  7. float awt =0,att=0, aw=0, at=0;
  8.  
  9. printf("Enter the process no : ");
  10. scanf("%d",&n);
  11.  
  12. for(int i=0; i<n; i++)
  13. {
  14. printf("Enter the burst time for process %d : ",i+1);
  15. cin>>b[i]>>arvTime[i];
  16. }
  17.  
  18. //sort(b,b+n);
  19.  
  20. for(int i=0; i<n; i++){
  21. for(int j=0; j<n; j++){
  22. if(b[i] <b[j]){
  23. temp = b[i];
  24. b[i] = b[j];
  25. b[j] = temp;
  26.  
  27. temp = arvTime[i];
  28. arvTime[i] = arvTime[j];
  29. arvTime[j] = temp;
  30.  
  31.  
  32. }
  33. }
  34. }
  35.  
  36.  
  37.  
  38. printf("Process \t bt \t wt \t tt");
  39.  
  40. for(int i=0; i<n; i++)
  41. {
  42. t = w-arvTime[i]+b[i];
  43. printf("\n %d \t\t %d \t %d \t %d", i+1,b[i],w-arvTime[i],t);
  44. at = at + t;
  45. aw = aw+w-arvTime[i];
  46. w = w+b[i];
  47.  
  48. }
  49. att = at/n;
  50. awt = aw/n;
  51.  
  52. printf("\n Average waiting time: %f and average turnedaround time: %f",awt,att);
  53.  
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment