-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcfs_b1856.c
70 lines (66 loc) · 1.72 KB
/
fcfs_b1856.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int i,j,n,*b,*a,*ta,*w,*r,*c,tasum=0,wsum=0,rsum=0;
float taavg,wavg,ravg;
printf("Enter number of processes:");
scanf("%d",&n);
b=malloc(n*sizeof(*b));
a=malloc(n*sizeof(*a));
ta=malloc(n*sizeof(*ta));
w=malloc(n*sizeof(*w));
r=malloc(n*sizeof(*r));
c=malloc(n*sizeof(*c));
for(i=0;i<n;i++)
c[i]=0;
for(i=0;i<n;i++)
{
printf("Enter the burst time for process %d: ",i+1);
scanf("%d",&b[i]);
printf("Enter the arrival time for process %d: ",i+1);
scanf("%d",&a[i]);
}
c[0]=b[0];
for(i=0;i<n;i++)
{
if(c[i]>a[i])
c[i]=c[i-1]+b[i];
else
c[i]=c[i-1]+(a[i]-c[i-1])+b[i];
}
for(i=0;i<n;i++)
{
ta[i]=c[i]-a[i];
tasum+=ta[i];
}
for(i=0;i<n;i++)
{
w[i]=ta[i]-b[i];
wsum+=w[i];
}
for(i=0;i<n;i++)
{
if(i==0)
{
r[i]=0-a[i];
rsum+=r[i];
continue;
}
r[i]=c[i-1]-a[i];
rsum+=r[i];
}
taavg=(float)tasum/n;
wavg=(float)wsum/n;
ravg=(float)rsum/n;
printf("Process\tBurst Time\tArrival Time\tTurnaround Time\tWaiting Time\tResponseTime\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%d\t%d\t%d\t%d\n",i+1,b[i],a[i],ta[i],w[i],r[i]);
}
printf("Average TurnAround Time:%f\n",taavg);
printf("Average Waiting Time:%f\n",wavg);
printf("Average Response Time:%f\n",ravg);
getch();
}