-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjfwarr.c
95 lines (94 loc) · 1.72 KB
/
sjfwarr.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<conio.h>
int flagging(int flag[],int n)
{
int i,temp=0;
for(i=0;i<n;i++)
if(flag[i]==0)
temp=1;
return temp;
}
int main()
{
int n,i,j,k,temp=0,time=0,tasum=0,wsum=0,rsum=0;
float tavg,wavg,ravg;
printf("\nEnter the number of processs:");
scanf("%d",&n);
int b[n],ord[n],a[n],c[n],f[n],t[n],r[n],w[n],flag[n];
printf("\nEnter the burst times:\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
flag[i]=0;
}
k=0;
printf("\nEnter the arrival timings:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
while(flagging(flag,n))
{
for(i=0;i<n;i++)
{
if(flag[i]==0)
{
temp=i;
}
else
{
continue;
}
for(j=0;j<n;j++)
{
if(a[j]<=time&&flag[j]==0)
{
if(b[temp]>=b[j])
temp=j;
}
}
ord[k++]=temp;
flag[temp]=1;
time+=b[temp];
printf("%d\t",b[temp]);
}
}
c[ord[0]]=b[ord[0]];
for(i=1;i<n;i++)
{
if(a[ord[i]]<c[ord[i-1]])
c[ord[i]]=c[ord[i-1]]+b[ord[i]];
else
c[ord[i]]=a[ord[i]]+b[ord[i]];
}
for(i=0;i<n;i++)
{
t[ord[i]]=c[ord[i]]-a[ord[i]];
tasum+=t[ord[i]];
}
for(i=0;i<n;i++)
{
w[ord[i]]=t[ord[i]]-b[ord[i]];
wsum+=w[ord[i]];
}
for(i=0;i<n;i++)
{
if(i==0)
{
r[ord[i]]=0;
continue;
}
r[ord[i]]=c[ord[i-1]]-a[ord[i]];
rsum+=r[ord[i]];
}
tavg=(float)tasum/n;
wavg=(float)wsum/n;
ravg=(float)rsum/n;
printf("\nProcess:\tBurst:\tArrival:\tTurnAround:\tWaiting:\tResponse:\n");
for(i=0;i<n;i++)
printf("%d\t\t%d\t%d\t\t%d\t\t%d\t\t%d\n",i+1,b[i],a[i],t[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();
}