Skip to content

Instantly share code, notes, and snippets.

@prashantsolanki3
Created January 23, 2016 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantsolanki3/a77af8062380d600f969 to your computer and use it in GitHub Desktop.
Save prashantsolanki3/a77af8062380d600f969 to your computer and use it in GitHub Desktop.
OS First Come First Serve Exp-1
#include<iostream.h>
#include<conio.h>
int main() {
int n,burst[20],wait[20],tat[20],avgwt=0,avgtat=0,i,j;
clrscr();
cout<<"Enter total number of processes(maximum 20):";
cin>>n;
cout<<"\nEnter Process Burst Time\n";
for(i=0;i<n;i++)
{ //Get Process burst time from user
cout<<"P["<<i+1<<"]:";
cin>>burst[i];
}
wait[0]=0; //waiting time for first process should be set to 0.
//calculating waiting time for every process.
for(i=1;i<n;i++){
wait[i]=0;// Set wait = 0 before adding burst time.
for(j=0;j<i;j++)
wait[i]+=burst[j];
}
cout<<"\nProcess\tBurst Time\tWaiting Time\tTurnaround Time";
//calculating turnaround time
for(i=0;i<n;i++){
tat[i]=burst[i]+wait[i];
avgwt+=wait[i];
avgtat+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t"<<burst[i]<<"\t\t"<<wait[i]<<"\t\t"<<tat[i];
}
avgwt/=n;
avgtat/=n;
cout<<"\n\nAverage Waiting Time:"<<avgwt;
cout<<"\nAverage Turnaround Time:"<<avgtat;
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment