-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path1a_FCFS.c
72 lines (61 loc) · 1.59 KB
/
1a_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
int i, n;
float tatAvg, wtAvg;
void read(int b[]) {
for (i = 0; i < n; ++i) {
printf("Enter the burst time of process %d: ", i);
scanf("%d", &b[i]);
}
}
void findWaitingtime(int b[], int wt[]) {
wt[0] = 0;
int wtSum = 0;
for (i = 1; i < n; ++i) {
wt[i] = wt[i - 1] + b[i - 1];
wtSum += wt[i];
}
wtAvg = (float)wtSum / n;
}
void findTurnAroundtime(int tat[], int b[], int wt[]) {
int tatSum = 0;
for (i = 0; i < n; ++i) {
tat[i] = b[i] + wt[i];
tatSum += tat[i];
}
tatAvg = (float)tatSum / n;
}
void display(int b[], int wt[], int tat[]) {
printf("Process\tBurstTime WaitingTime TurnAroundTime\n");
for (i = 0; i < n; ++i) {
printf("%d\t%d\t\t%d\t%d\n", i, b[i], wt[i], tat[i]);
}
printf("average waiting time: %f", wtAvg);
printf("\naverage turnaround time: %f", tatAvg);
printf("\n");
}
void calcTime(int b[]) {
int wt[20], tat[20];
findWaitingtime(b, wt);
findTurnAroundtime(tat, b, wt);
display(b, wt, tat);
}
int main() {
int b[20];
printf("Number of Processes:");
scanf("%d", &n);
read(b);
calcTime(b);
return 0;
}
/* OUTPUT
Number of Processes:3
Enter the burst time of process 0: 23
Enter the burst time of process 1: 33
Enter the burst time of process 2: 11
Process BurstTime WaitingTime TurnAroundTime
0 23 0 23
1 33 23 56
2 11 56 67
average waiting time: 26.333334
average turnaround time: 48.666668
*/