-
Notifications
You must be signed in to change notification settings - Fork 0
/
roundrobin.c
78 lines (78 loc) · 1.77 KB
/
roundrobin.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>
#include<conio.h>
int flagging(int bc[],int n)
{
int i,t=0;
for(i=0;i<n;i++)
if(bc[i]!=0)
return t+1;
return t;
}
int main()
{
int n,i,q,temp,k=0,tsum=0,wsum=0,rsum=0,t=0;
printf("Enter number of process: ");
scanf("%d",&n);
printf("Enter Quantum Value: ");
scanf("%d",&q);
int b[n],bc[n],ta[n],w[n],r[n],c[n],fi[n],flag[n];
float tavg,wavg,ravg;
printf("Enter burst times:\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
bc[i]=b[i];
flag[i]=0;
}
while(flagging(bc,n))
{
for(i=0;i<n;i++)
{
if(bc[i]==0)
continue;
if(!flag[i])
{
fi[i]=t;
flag[i]=1;
}
if(bc[i]>q)
{
bc[i]-=q;
t+=q;
}
else
{
temp=bc[i];
bc[i]=0;
t+=temp;
c[i]=t;
}
k++;
}
}
for(i=0;i<n;i++)
{
ta[i]=c[i];
tsum+=ta[i];
}
for(i=0;i<n;i++)
{
w[i]=ta[i]-b[i];
wsum+=w[i];
}
for(i=0;i<n;i++)
{
r[i]=fi[i];
rsum+=r[i];
}
tavg=(float)tsum/n;
wavg=(float)wsum/n;
ravg=(float)rsum/n;
printf("Process\tBurstTime\tTurnaround\tWaiting\tResponse\n");
for(i=0;i<n;i++)
printf("%d\t%d\t\t%d\t\t%d\t%d\n",i+1,b[i],ta[i],w[i],r[i]);
printf("Average TurnAround Time:%.2f\n",tavg);
printf("Average Waiting Time:%.2f\n",wavg);
printf("Average Response Time:%.2f\n",ravg);
getch();
}