forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCFS Scheduling Operating System
37 lines (37 loc) · 998 Bytes
/
FCFS Scheduling Operating System
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,bt[10],wt[10],tat[10];//array,to take burst,waiting,turn around time
float avwt=0,avtat=0;
cout<<"Enter number of processes:";
cin>>n;
cout<<"\nEnter Process's Burst Time\n";
int i,j;
for(i=0;i<n;i++)
{
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
}
wt[0]=0; //waiting time for first process is 0
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time";//calculating turnaround time
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
}
avwt=(float)avwt/i;
avtat=(float)avtat/i;
cout<<"\n\nAverage Waiting Time:"<<setprecision(2)<<avwt;
cout<<"\nAverage Turnaround Time:"<<setprecision(2)<<avtat;
return 0;
}