-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF.C.F.S.c
59 lines (59 loc) · 1.1 KB
/
F.C.F.S.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
#include<conio.h>
#include<stdio.h>
struct pr{
int pi,ex,at,ta,w;
}*t;
int wait(int);
int turn(int);
void main()
{
int n,i,tex,*g,j,f;
printf("enter number of processes...");
scanf("%d",&n);
t=(struct pr *)calloc(n,sizeof(struct pr));
for(i=0;i<n;i++){
printf("enter pi,ex,at for %d process...\n",i+1);
scanf("%d %d %d",&t[i].pi,&t[i].ex,&t[i].at);
t[i].w=wait(i);
t[i].ta=turn(i);
}
printf("\nTable..\npi\tex\tat\tta\tw\n--------------------------------------\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\t%d\t%d\n",t[i].pi,t[i].ex,t[i].at,t[i].ta,t[i].w);
tex=t[n-1].ta+t[n-1].at;
printf("\n\nGraph..\npi\t");
for(i=0;i<=tex;i++)
printf("%0.2d ",i);
printf("\n");
for(i=0;i<n;i++)
{
f=0;
printf("%d\t",i+1);
for(j=0;j<=tex;j++)
{
if(t[i].at==j)
printf("| ");
else if(j<t[i].ta+t[i].at&&j>t[i].w+t[i].at)
printf("- ");
else if(j==t[i].ta+t[i].at)
printf("| ");
else
printf(" ");
}
printf("\n");
}
}
int wait(int a)
{
int s;
if(a==0)
return 0;
s=t[a-1].ta+t[a-1].at-t[a].at;
if(s<0)
return 0;
return s;
}
int turn(int a)
{
return t[a].w+t[a].ex;
}