-
Notifications
You must be signed in to change notification settings - Fork 0
/
SJF_Preem_Foij.cpp
48 lines (40 loc) · 1.17 KB
/
SJF_Preem_Foij.cpp
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
#include <stdio.h>
int main()
{
int arrival_time[10], burst_time[10], temp[10], end;
int i, smallest, count = 0, time, n,wait_time = 0;
float average_waiting_time;
printf("\nEnter the Total Number of Processes:\t");
scanf("%d", &n);
printf("\nEnter Details of %d Processes\n", n);
for(i = 0; i < n; i++)
{
printf("\nEnter Arrival Time:\t");
scanf("%d", &arrival_time[i]);
printf("Enter Burst Time:\t");
scanf("%d", &burst_time[i]);
temp[i] = burst_time[i];
}
burst_time[n]=9999;
for(time = 0; count != n; time++)
{
smallest = n;
for(i = 0; i < n; i++)
{
if(arrival_time[i] <= time && burst_time[i] < burst_time[smallest] && burst_time[i] > 0)
{
smallest = i;
}
}
burst_time[smallest]--;
if(burst_time[smallest] == 0)
{
count++;
end = time + 1;
wait_time = wait_time + end - arrival_time[smallest] - temp[smallest];
}
}
average_waiting_time = wait_time / n;
printf("\n\nAverage Waiting Time:\t%lf\n", average_waiting_time);
return 0;
}