Created
January 23, 2016 04:10
-
-
Save prashantsolanki3/a77af8062380d600f969 to your computer and use it in GitHub Desktop.
OS First Come First Serve Exp-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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