-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcfs.c
More file actions
59 lines (59 loc) · 1.37 KB
/
Copy pathfcfs.c
File metadata and controls
59 lines (59 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
void main()
{
int n,i,j;
double avg_wait=0,avg_tat=0;
printf("Enter the number of processes: ");
scanf("%d",&n);
int btime[n],wtime[n],ttime[n];
printf("Enter the burst time of the processes\n");
for(i=0;i<n;i++)
{
printf("P%d Burst time: ",(i+1));
scanf("%d",&btime[i]);
}
wtime[0]=0;
for(i=0;i<n;i++)
{
wtime[i]=wtime[i-1]+btime[i-1];
avg_wait=avg_wait+wtime[i];
}
avg_wait=avg_wait/n;
for(i=0;i<n;i++)
{
ttime[i]=wtime[i]+btime[i];
avg_tat=avg_tat+ttime[i];
}
avg_tat=avg_tat/n;
printf("Process\tBurst time\tWait time\tTurn around time\n");
for(i=0;i<n;i++)
{
printf("P%d\t%d\t\t%d\t\t%d\n",i+1,btime[i],wtime[i],ttime[i]);
}
printf("\n");
printf("Average waiting time: %.2f\nAverage turn around time: %.2f\n",avg_wait,avg_tat);
printf("\n");
printf(" ");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n|");
for(i=0;i<n;i++)
{
printf("P%d |",i+1);
}
printf("\n|");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n0\t");
int current_time=0;
for(i=0;i<n;i++)
{
current_time=current_time+btime[i];
printf("%d\t",current_time);
}
printf("\n");
}