-
Notifications
You must be signed in to change notification settings - Fork 4
/
fcfc.c
97 lines (78 loc) · 1.75 KB
/
fcfc.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
96
97
#include<stdio.h>
#include<string.h>
struct process
{
char id[10];
int AT,BT,WT,TAT;
}P[10];
struct done
{
char id[10];
int AT,CT;
}D[10];
void fcfs(int);
int main()
{
int n,i=0;
printf("\nEnter the number of process : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nPROCESS %d\n",i+1);
printf("Enter the Process ID : ");
scanf("%s",P[i].id);
printf("Enter the Arrival Time : ");
scanf("%d",&P[i].AT);
printf("Enter the Burst Time : ");
scanf("%d",&P[i].BT);
}
fcfs(n);
}
void fcfs(int n)
{
int TT=0,count=0,i=0,k=0;
float TAWT=0.0,TATAT=0.0;
while(count<n)
{
if(TT < P[i].AT)
{
strcpy(D[k].id,"IDLE");
D[k].AT=TT;
D[k].CT=P[i].AT;
TT=P[i].AT;
k++;
}
else
{
strcpy(D[k].id,P[i].id);
D[k].AT=TT;
D[k].CT=TT+P[i].BT;
TT=TT+P[i].BT;
P[i].TAT=TT-P[i].AT;
P[i].WT=P[i].TAT-P[i].BT;
TAWT=TAWT+P[i].WT;
TATAT=TATAT+P[i].TAT;
i++;
k++;
count++;
}
}
TAWT=TAWT/n;
TATAT=TATAT/n;
printf("\n\nGANTT CHART ");
printf("\n\t--------------------------------------------------------------------\n\t");
for(i=0;i<k;i++)
{
printf("|");
printf("%s\t",D[i].id);
}
printf(" |");
printf("\n\t--------------------------------------------------------------------\n\t");
for(i=0;i<k;i++)
{
printf("%d\t",D[i].AT);
}
printf("%d\t\n",D[k-1].CT);
printf("\nAVERAGE WAITING TIME : %f",TAWT);
printf("\nAVERAGE TURNAROUND TIME : %f\n",TATAT);
}