-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoundRobin.txt
95 lines (94 loc) · 2.26 KB
/
RoundRobin.txt
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>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f\n",turnaround_time*1.0/n);
int count1,j1,n1,time1,remain1,flag1=0,time_quantum2;
int wait_time1=0,turnaround_time1=0,at1[10],bt1[10],rt1[10];
printf("Enter Total Process:\t ");
scanf("%d",&n1);
remain1=n1;
for(count1=0;count1<n1;count1++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at1[count1]);
scanf("%d",&bt1[count1]);
rt1[count1]=bt1[count1];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum2);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time1=0,count1=0;remain1!=0;)
{
if(rt1[count1]<=time_quantum2 && rt1[count1]>0)
{
time1+=rt1[count1];
rt1[count1]=0;
flag1=1;
}
else if(rt1[count1]>0)
{
rt1[count1]-=time_quantum2;
time1+=time_quantum2;
}
if(rt1[count1]==0 && flag1==1)
{
remain1--;
printf("P[%d]\t|\t%d\t|\t%d\n",count1+1,time1-at1[count1],time1-at1[count1]-bt1[count1]);
wait_time1+=time1-at1[count1]-bt1[count1];
turnaround_time1+=time1-at1[count1];
flag1=0;
}
if(count1==n1-1)
count1=0;
else if(at1[count1+1]<=time1)
count1++;
else
count1=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time1*1.0/n1);
printf("Avg Turnaround Time = %f",turnaround_time1*1.0/n1);
}