-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrr.cpp
More file actions
69 lines (61 loc) · 1.86 KB
/
rr.cpp
File metadata and controls
69 lines (61 loc) · 1.86 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
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
int main()
{
int i, limit, total = 0, x, counter = 0, tq;
int wt = 0, tat = 0, at[10], bt[10], temp[10];
float awt, atat;
printf("\nEnter Total Number of Processes:\t");
scanf("%d", &limit);
x = limit;
for(i = 0; i < limit; i++)
{
printf("\nEnter Details of Process[%d]\n", i + 1);
printf("Arrival Time:\t");
scanf("%d", &at[i]);
printf("Burst Time:\t");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
printf("\nEnter Time Quantum:\t");
scanf("%d", &tq);
printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\n");
for(total = 0, i = 0; x != 0;)
{
if(temp[i] <= tq && temp[i] > 0)
{
total = total + temp[i];
temp[i] = 0;
counter = 1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - tq;
total = total + tq;
}
if(temp[i] == 0 && counter == 1)
{
x--;
printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1, bt[i], total - at[i], total - at[i] - bt[i]);
wt = wt + total - at[i] - bt[i];
tat = tat + total - at[i];
counter = 0;
}
if(i == limit - 1)
{
i = 0;
}
else if(at[i + 1] <= total)
{
i++;
}
else
{
i = 0;
}
}
awt = wt * 1.0 / limit;
atat = tat * 1.0 / limit;
printf("\n\nAverage Waiting Time:\t%f", awt);
printf("\nAvg Turnaround Time:\t%f\n", atat);
return 0;
}