-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfcfs.c
37 lines (32 loc) · 851 Bytes
/
fcfs.c
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 <stdio.h>
struct proc{
int pid;
int wtime;
int btime;
int ttime;
};
void main(){
int n;
float totalwtime = 0;
float combinedwait = 0;
printf("Enter number of process : ");
scanf("%d" , &n);
struct proc p[n];
for(int i=0 ; i<n ;i++){
printf("Process %d burst time : " , i);
scanf("%d" , &p[i].btime);
p[i].pid = i+1;
}
for(int i=0 ; i<n ; i++){
p[i].wtime = totalwtime;
combinedwait += totalwtime;
totalwtime += p[i].btime;
p[i].ttime = p[i].wtime + p[i].btime;
}
printf("\nPID\tBURST TIME\tWAIT TIME\tTURNAROUND TIME\n");
for(int i=0 ; i<n ; i++){
printf("%d\t%d\t\t%d\t\t%d\n" , p[i].pid , p[i].btime , p[i].wtime , p[i].ttime);
}
printf("Average Wait Time : %.2f\n" , combinedwait/n);
return;
}