Advertisement
Marufcse

First Come First Serve With SJF c++

Nov 24th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.      int bt[20],p[20],i,j,total=0,pos,temp,number,store =0;;
  7.     float avrgwait=0;
  8.     cout<<"Enter the number of process: ";
  9.     cin>>number;
  10.     int burst[number+1], wait[number+1], turnar[number];
  11.     wait[0]=0;
  12.  
  13.     for(i=1; i<=number; i++)
  14.     {
  15.         cout<<"Input Burst Time for P"<<i<<" : ";
  16.         cin>>burst[i];
  17.     }
  18.  
  19.      //sorting burst time in ascending order using selection sort
  20.     for(i=0;i<number;i++)
  21.     {
  22.         pos=i;
  23.         for(j=i+1;j<number;j++)
  24.         {
  25.             if(burst[j]<burst[pos])
  26.                 pos=j;
  27.         }
  28.  
  29.         temp=burst[i];
  30.         burst[i]=burst[pos];
  31.         burst[pos]=temp;
  32.  
  33.         temp=p[i];
  34.         p[i]=p[pos];
  35.         p[pos]=temp;
  36.        
  37.        
  38.     }
  39.      cout<<"The Brust Time In ascending "<<endl;
  40.      for(i=1; i<=number; i++){
  41.          
  42.    
  43.         cout<<"Brust for P"<<i<<":"<<burst[i]<<endl;
  44.    
  45.      }
  46.      for(i=1; i<=number; i++)
  47.     {
  48.         store = wait[i-1] + burst[i];
  49.         wait[i] = store;
  50.         avrgwait = avrgwait + wait[i-1];
  51.         cout<<"Waiting time for P"<<i<<" : "<<wait[i-1]<<endl;
  52.     }
  53.  
  54.     for(i=0; i<number; i++)
  55.     {
  56.         turnar[i] = wait[i+1];
  57.         cout<<"Turn around time  P"<<i+1<<" : "<<turnar[i]<<endl;
  58.     }
  59.     cout<<"Average wait time: "<<avrgwait/number<<endl;
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement