-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROUND ROBIN.c
72 lines (72 loc) · 2.19 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
//Round Robin Scheduling//
//Alin Babu,7,R5//
#include<stdio.h>
int burst_time[20],wait_time[20],turn_time[20],i,j,n;
int rt[20],arrival_time[20],time_quantum;
float avturn_time,avwait_time,tturn_time,twait_time;
void WaitTurnaround_Time();
void display();
int main()
{
printf("Enter the number of process\n");
scanf("%d",&n);
printf("Enter the time quantum\n");
scanf("%d",&time_quantum);
printf("Enter the Burst time and Arrival Time of each process\n");
for(i=0;i<n;i++)
{
printf("P[%d] :",i+1);
scanf("%d\t",&burst_time[i]);
scanf("%d",&arrival_time[i]);
rt[i]=burst_time[i]; //For Temporary Storage of burst time for calculation//
}
WaitTurnaround_Time();
display();
return 0;
}
void WaitTurnaround_Time() //Function to calculate Waiting Time and Turn Around Time//
{
int time,remain,flag;
remain=n;
for(time=0,i=0;remain!=0;)
{
if(rt[i]<=time_quantum && rt[i]>0)
{
time+=rt[i];
rt[i]=0;
flag=1;
}
else if(rt[i]>0)
{
rt[i]-=time_quantum;
time+=time_quantum;
}
if(rt[i]==0 && flag==1)
{
remain--;
turn_time[i]=time-arrival_time[i];
wait_time[i]=time-arrival_time[i]-burst_time[i];
twait_time+=wait_time[i];
tturn_time+=turn_time[i];
flag=0;
}
if(i==n-1)
i=0;
else if(arrival_time[i+1]<=time)
i++;
else
i=0;
}
avwait_time=twait_time/n;
avturn_time=tturn_time/n;
}
void display() //To display waiting time,turnaround time,averge waiting time and turnaround time//
{
printf(" Process\t\tBurst Time\t\tArrival Time\t\tWaiting Time\t\tTurnaround Time\n");
for(i=0;i<n;i++)
{
printf(" P[%d]\t\t\t%d\t\t\t%d\t\t\t%d\t\t\t%d\n",i+1,burst_time[i],arrival_time[i],wait_time[i],turn_time[i]);
}
printf("Averge Waiting Time :%.2f\n",avwait_time);
printf("Averge Turnaround Time :%.2f\n",avturn_time);
}