-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsjf_no_arivaltime.c
60 lines (51 loc) · 1.41 KB
/
sjf_no_arivaltime.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
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}
//sorting of burst times
for (int i = 0; i < n - 1; i++){
int temp = 0;
for (int j = 0; j < n - i - 1; j++){
if (bt[j] > bt[j + 1]){
//sorting burst time
temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
//sorting process list
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n;
total=0;
printf("\nProcess\tBurst Time\ttWaiting Time\tTurnaround Time\n");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n;
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}