-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority.c
65 lines (57 loc) · 1.39 KB
/
priority.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
#include <stdio.h>
int main()
{
int n;
printf("enter the number of processes: ");
scanf("%d", &n);
float bt[n], prt[n], seq[n];
for (int i = 0; i < n; i++)
{
printf("\nenter the burst time of process %d: ", i);
scanf("%f", &bt[i]);
printf("enter the priority of process %d: ", i);
scanf("%f", &prt[i]);
seq[i]=i;
}
int tempp = 0, tempbt = 0, temps =0;
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (prt[i]>prt[j])
{
tempp = prt[i];
prt[i] = prt[j];
prt[j] = tempp;
tempbt = bt[i];
bt[i] = bt[j];
bt[j] = tempbt;
temps = seq[i];
seq[i] = seq[j];
seq[j] =temps;
}
}
}
float wt[n];
wt[0]=0;
float wtsum=0;
for (int i = 1; i < n; i++)
{
wt[i]=wt[i-1]+bt[i-1];
wtsum += wt[i];
}
float tt[n];
float ttsum = 0;
for (int i = 0; i < n; i++)
{
tt[i]=wt[i]+bt[i];
ttsum += tt[i];
}
printf("\nSequence of Processes: P%.0f", seq[0]);
for (int i = 1; i < n; i++)
{
printf(" -> P%.0f", seq[i]);
}
printf("\n\nAverage waiting time = %.2f ms\nAverage turnaround time = %.2f ms\n\n", wtsum/n, ttsum/n);
return 0;
}