-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRR_Arr.c
78 lines (77 loc) · 1.41 KB
/
RR_Arr.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>
struct process {
int pno,bt,at,cbt,tat,wt;
};
void main()
{
int n,i,j,tq;
float ttat,twt,atwt,atat;
printf("Enter the number of process : ");
scanf("%d",&n);
struct process p[n],temp;
printf("Enter the Process no. Arrival time and Burst time of :-\n");
for(i=0;i<n;i++){
printf("Process %d : ",i);
scanf("%d %d %d",&p[i].pno,&p[i].at,&p[i].bt);
p[i].cbt=p[i].bt;
}
printf("Enter the time quantum : ");
scanf("%d",&tq);
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(p[i].at>p[j].at){
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
/*printf("Sorted array is : \n");
for(i=0;i<n;i++) {
printf("%d %d %d\n",p[i].pno,p[i].at,p[i].bt);
}*/
printf("\nGANTT CHART\n0");
int x=0,y=0,t=0;
i=0;
while(1) {
if(p[i].at<=t) {
if(p[i].bt>0) {
if(p[i].bt>tq) {
x=x+tq;
p[i].bt-=tq;
printf(" P%d %d",p[i].pno,x);
t+=tq;
}
else {
x=x+p[i].bt;
p[i].tat=x;
p[i].wt=p[i].tat-p[i].cbt;
p[i].bt=0;
y++;
printf(" P%d %d",p[i].pno,x);
t+=tq;
if(y==n){
break;
}
}
}
if(i==n-1) {
i=0; }
else {
i++; }
}
else {
t=p[i].at;
}
}
printf("\n\nProcess no.\tArrival time\tBurst time\tTurnaround time\tWaiting time\n");
for(i=0;i<n;i++) {
printf("P%d\t\t%d\t\t%d\t\t%d\t\t%d\n",p[i].pno,p[i].at,p[i].cbt,p[i].tat,p[i].wt);
}
ttat=p[n-1].tat;
twt=p[n-1].wt;
atat=ttat/n;
atwt=twt/n;
printf("Average Turnaround time = %f\n",atat);
printf("Average Waiting time = %f\n",atwt);
}