-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCFS.c
56 lines (56 loc) · 1.24 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
int burst_time[20],wait_time[20],turn_time[20],i,j,n;
float tturn_time,twait_time,avturn_time,avwait_time;
void Wait_Time();
void Turnaround_Time();
void display();
int main()
{
printf("Enter the number of process\n");
scanf("%d",&n);
printf("Enter the Burst time of each process\n");
for(i=0;i<n;i++)
{
printf("P[%d] :",i+1);
scanf("%d",&burst_time[i]);
}
Wait_Time();
Turnaround_Time();
display();
return 0;
}
void Wait_Time()
{
wait_time[0]=0;
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
wait_time[i]+=burst_time[j];
}
twait_time+=wait_time[i];
}
avwait_time=twait_time/n;
}
void Turnaround_Time()
{
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
turn_time[i]+=burst_time[j];
}
tturn_time+=turn_time[i];
}
avturn_time=tturn_time/n;
}
void display()
{
printf(" Process\t\tBurst Time\t\tWaiting Time\t\tTurnaround Time\n");
for(i=0;i<n;i++)
{
printf(" P[%d]\t\t\t%d\t\t\t%d\t\t\t%d\n",i+1,burst_time[i],wait_time[i],turn_time[i]);
}
printf("Averge Waiting Time :%.2f\n",avwait_time);
printf("Averge Turnaround Time :%.2f\n",avturn_time);
}