-
Notifications
You must be signed in to change notification settings - Fork 3
/
fcfs.c~
75 lines (40 loc) · 1.19 KB
/
fcfs.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
#include <stdio.h>
void main() {
int P[20],BT[20] ,WT[20] , TT[20];
int total_tt =0 , total_wt =0;
int i ,j, n;
double avg_wt , avg_tt;
printf("Enter the number of processes ");
scanf("%d",&n);
for(i=0 ; i<n;++i) {
printf("Enter the burst time for process %d :" , i+1);
scanf("%d" , &BT[i]);
P[i]=i+1;
}
WT[0]=0;
for(i=0 ;i<n;++i)
{ WT[i]=0;
for (j=0;j<i;j++)
{
WT[i] = WT[i] +BT[j];
}
total_wt += WT[i];
}
for(i=0;i<n;++i)
{
TT[i]= BT[i] +WT[i];
total_tt +=TT[i];
}
printf(" \n\n\tSHORTEST JOB FIRST SCHEDULING \n");
printf("\tPROCESS INFORMATION \n");
printf("_________________________\n");
printf(" PID | BURST TIME | WAITING TIME | TURNAROUND TIME \n");
for(i=0;i<n;++i)
{
printf("%d\t %d\t\t %d\t\t %d\t \n" , P[i] ,BT[i] ,WT[i] ,TT[i]);
}
avg_wt =total_wt/n;
avg_tt =total_tt/n;
printf ("\nAverage waiting time =%f \n " ,avg_wt );
printf ("\nAverage turnaround time =%f \n " ,avg_tt );
}