-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriority.c
More file actions
69 lines (58 loc) · 1.5 KB
/
priority.c
File metadata and controls
69 lines (58 loc) · 1.5 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
#include<stdio.h>
void main()
{
int i,j,pid[10],bt[10],p[10],wt[10],tat[10],n,t,total_wt=0,total_tat=0;
float avg_wt,avg_tat;
printf("Enter the total num of processes:");
scanf("%d",&n);
printf("Enter the PID , Bt and priority:");
for(i=0;i<n;i++)
{
scanf("%d%d%d",&pid[i],&bt[i],&p[i]);
}
//sorting the processes based on priority
for(i=0;i<n;i++)
{
//j=i;
for(j=i+1;j<n;j++)
{
//int flag=0;
if(p[i]>p[j])
{
t=p[i];
p[i]=p[j];
p[j]=t;
t=pid[i];
pid[i]=pid[j];
pid[j]=t;
t=bt[i];
bt[i]=bt[j];
bt[j]=t;
// j=j;
}
// int t;
}
}
wt[0]=0;
tat[0]=wt[0]+bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=wt[i]+bt[i];
}
for(i=0;i<n;i++)
{
total_wt+=wt[i];
total_tat+=tat[i];
}
// printf("%d",n);
avg_wt = total_wt/n;
avg_tat =total_tat/n;
printf("PID\tBT\tp\tWT\tTAT");
for(int i=0;i<n;i++)
{
printf("\n%d\t%d\t%d\t%d\t%d",pid[i],bt[i],p[i],wt[i],tat[i]);
}
//printf("\n%d\t%d",total_wt,total_tat);
printf("\nAverage Wt: %f \nAverage tat: %f",avg_wt,avg_tat);
}