-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcfs with arrival time.c
79 lines (66 loc) · 1.57 KB
/
fcfs with arrival time.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
int main()
{
int n, i, j, sum=0, avg_wt=0, avg_tat=0, min_loc, min, max, count=0;
printf("Enter the number of process: ");
scanf("%d", &n);
int bt[n], at[n], proc[n], tat[n], wt[n], res[n];
printf("Enter the %d process's arrival & burst time\n", n);
for(i=0; i<n; i++)
{
printf("P%d = ", i+1);
scanf("%d%d", &at[i], &bt[i]);
if(count == 0)
{
max = at[i];
min = at[i];
count++;
}
else
{
if(at[i] < min)
{
min = at[i];
min_loc = i;
}
if(at[i] > max)
{
max = at[i];
}
}
}
sum = at[min_loc];
for(i=0; i<n; i++)
{
sum += bt[min_loc];
res[i] = sum;
proc[i] = min_loc;
tat[i] = res[i] - at[min_loc];
wt[i] = tat[i] - bt[min_loc];
at[min_loc] = ++max;
min = ++max;
for(j=0; j<n; j++)
{
if(at[j] < min)
{
min = at[j];
min_loc = j;
}
}
}
printf("\nGantt chart->\n");
for(i=0; i<n; i++)
{
printf("P%d = %d\n", proc[i]+1, res[i]);
}
printf("\n\tCT\tTAT\tWT\n");
for(i=0; i<n; i++)
{
printf("P%d\t%d\t%d\t%d\n", proc[i]+1, res[i], tat[i], wt[i]);
avg_tat += tat[i];
avg_wt += wt[i];
}
printf("\nAverage waiting time = %d\n", avg_wt/n);
printf("Average turn-around time = %d\n", avg_tat/n);
return 0;
}