-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRound Robin.c
95 lines (86 loc) · 1.38 KB
/
Round Robin.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<stdio.h>
#include<stdbool.h>
void FindWT(int Pr , int Burst[] , int Qn , int WT[])
{
int Time=0;
int Rem[Pr];
for(int i=0 ; i<Pr ; i++)
{
Rem[i]=Burst[i];
}
while(1)
{
bool Dn=true;
for(int i=0 ; i<Pr ; i++)
{
if(Rem[i]>0)
{
Dn=false;
printf("%d" , Time);
if(Rem[i]>Qn)
{
Time+=Qn;
Rem[i]-=Qn;
}
else
{
Time+=Rem[i];
WT[i]=Time-Burst[i];
Rem[i]=0;
}
printf("->P[%d] " , i+1);
}
}
if(Dn==true)
{
break;
}
}
}
void FindTAT(int WT[] , int BT[] , int TAT[] , int Pr)
{
for(int i=0 ; i<Pr ; i++)
{
TAT[i]=WT[i]+BT[i];
}
}
void Checker(int Pr , int Burst[] , int Qn)
{
int TtlWT , TtlTAT;
int WT[Pr] , TAT[Pr];
FindWT(Pr , Burst, Qn , WT);
FindTAT(WT , Burst , TAT , Pr);
float AB=0;
float CD=0;
for(int i=0 ; i<Pr ; i++)
{
AB+=WT[i];
CD+=TAT[i];
}
AB/=Pr;
CD/=Pr;
printf("\n");
printf("\n");
printf("THE AVERAGE WAITING TIME IS : %f\n" , AB);
printf("THE AVERAGE TURN AROUND TIME IS : %f\n" , CD);
}
int main()
{
int Proc;
printf("ENTER TOTAL PROCESS : ");
scanf("%d" , &Proc);
printf("\n");
int Process[Proc];
int Burst[Proc];
for(int i=0 ; i<Proc ; i++)
{
printf("BURST TIME FOR P[%d] : " , i+1);
scanf("%d" , &Burst[i]);
}
printf("\n");
printf("ENTER QUANTAM TIME : ");
int Quan;
scanf("%d" , &Quan);
printf("\n");
Checker(Proc , Burst , Quan);
}