-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFirst_Come_First_Serve.c
More file actions
66 lines (54 loc) · 1.05 KB
/
First_Come_First_Serve.c
File metadata and controls
66 lines (54 loc) · 1.05 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
// Scheduling Algorithm
// first come first scheduling algorithm
#include <stdio.h>
struct process
{
int pid;
int bt;
int wt;
int tat;
}p[50];
int main()
{
// initialize variables
int n,temp,i,j;
printf("Please Enter no of processes : ");
scanf("%d",&n);
printf("\nPlease Enter Burst Time of processes : \n");
for(i=0;i<n;i++)
{
printf("P%d : ",i+1);
p[i].pid = i+1;
scanf("%d",&p[i].bt);
}
// wt&tat
for(i=0;i<n;i++)
{
if(i==0)
{
p[i].wt = 0;
p[i].tat = p[i].wt + p[i].bt;
continue;
}
p[i].wt = p[i-1].bt + p[i-1].wt;
p[i].tat = p[i].wt + p[i].bt;
}
// print
printf("\nPid\tBT\tWT\tTAT\n");
for(i=0;i<n;i++)
{
printf("%d\t%d\t%d\t%d\n",p[i].pid,p[i].bt,p[i].wt,p[i].tat);
}
// Avg wt
temp = 0;
for(i=0;i<n;i++)
temp += p[i].wt;
printf("\ntotal waiting time\t\t:%d\n", temp);
printf("average waiting time\t\t:%f\n",(float)temp/n);
// Avg tat
temp = 0;
for(i=0;i<n;i++)
temp += p[i].tat;
printf("total turn around time\t\t:%d\n",temp);
printf("average turn around time\t:%f\n",(float)temp/n);
}