-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjf.c
59 lines (49 loc) · 1.29 KB
/
sjf.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<stdio.h>
void main()
{
int numberofprocess;
int bt[10],ct[10],nm[10];
float ttat = 0,twt = 0,tat[10],wt[10];
printf("\nEnter the number of processes that you need to enter:\n");
scanf("%d",&numberofprocess);
printf("Enter the burst time of each process in order:\n");
for(int i=0;i<numberofprocess;i++)
{
scanf("%d",&bt[i]);
nm[i]=i;
}
for(int i=0;i<numberofprocess-1;i++)
{
for(int j=0;j<numberofprocess-i-1;j++)
{
if(bt[j]>bt[j+1])
{
int temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
temp = nm[j];
nm[j] = nm[j+1];
nm[j+1] = temp;
}
}
}
ct[-1]=0;
for(int i=0;i<numberofprocess;i++)
{
ct[i] = ct[i-1] + bt[i];
tat[i] = ct[i];
wt[i] = ct[i] - bt[i];
}
printf("\nPROCESS NO. BURST TIME TURNAROUND TIME WAITING TIME\n");
for(int i=0;i<numberofprocess;i++)
{
printf("P[%d] %d %f %f\n",nm[i],bt[i],tat[i],wt[i]);
}
for(int i=0;i<numberofprocess;i++)
{
ttat = ttat + tat[i];
twt = twt + wt[i];
}
printf("\nAverage Turnaround Time: %f\n",ttat/numberofprocess);
printf("\nAverage Waiting Time: %f\n",twt/numberofprocess);
}