-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfcfs scheduling
More file actions
97 lines (90 loc) · 1.65 KB
/
fcfs scheduling
File metadata and controls
97 lines (90 loc) · 1.65 KB
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
fcfs.c
Last month
Sep 5
You edited an item
C
fcfs.c
Earlier this year
Aug 31
You shared an item
C
fcfs.c
A
Can edit
ADITHYA ANIL B.Tech CSE A 2017 - 2021
Aug 31
You uploaded an item
C
fcfs.c
#include<stdio.h>
int main()
{
int n,p[10], bt[20], wt[20], ct[20], tat[20], at[20],c=0,tot=0,temp,i, j;
float avgwt=0, avgtat=0;
printf("Enter the number of processes:");
scanf("%d", &n);
printf("Enter the burst time for each process:");
for(i=0;i<n;i++)
{ printf("p[%d]",i+1);
p[i]=i+1;
scanf("%d", &bt[i]);
}
printf("Enter the arrival time for each process:");
for(i=0;i<n;i++)
{ printf("p[%d]",i+1);
p[i]=i+1;
scanf("%d", &at[i]);
}
for(i=0; i<n; i++) {
for(j=0; j<n; j++) {
if(at[i]< at[j])
{
temp = p[j];
p[j] = p[i];
p[i] = temp;
temp = at[j];
at[j] = at[i];
at[i] = temp;
temp = bt[j];
bt[j] = bt[i];
bt[i] = temp;
}
}
}
c=at[0];
for(i=0;i<n;i++)
{c=c+bt[i];
ct[i]=c;
}
for(i=0;i<n;i++)
{tat[i]=ct[i]-at[i];
tot+=tat[i];
}
avgtat=(float)tot/n;
tot=0;
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
tot+=wt[i];
}
avgwt=(float)tot/n;
printf("\nProcess\tArrival time\tBurst Time\tWaiting Time\tCompletion time\tTurn around time\t");
for(i=0;i<n;i++)
{printf("\np[%d]\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n",p[i],at[i],bt[i],wt[i], ct[i],tat[i]);
}
printf("\nAvg. WT:%f",avgwt);
printf("\nAvg. TAT:%f",avgtat);
printf("\n");
for(i=0;i<n;i++)
{
printf("| P%d",i);
}
printf("|");
printf("\n%d",at[0]);
for(i=0;i<n;i++)
{
printf("\t%d",ct[i]);
}
printf("\n");
return 0;
}