-
Notifications
You must be signed in to change notification settings - Fork 0
/
priority.c
70 lines (58 loc) · 1.6 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
62
63
64
65
66
67
68
69
70
#include <stdio.h>
void main()
{
int numberofprocess;
int bt[10],ct[10],nm[10],priority[10];
int tat[10],wt[10];
float ttat = 0,twt = 0;
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;
}
printf("Enter the priority of each process in order:\n");
for(int i=0;i<numberofprocess;i++)
{
scanf("%d",&priority[i]);
}
for(int i=0;i<numberofprocess-1;i++)
{
for (int j=0;j<numberofprocess-i-1;j++)
{
if(priority[j] > priority[j+1])
{
int temp = nm[j];
nm[j] = nm[j+1];
nm[j+1] = temp;
temp = bt[j];
bt[j] = bt[j+1];
bt[j+1] = temp;
temp = priority[j];
priority[j] = priority[j+1];
priority[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 PRIORITY TURNAROUND TIME WAITING TIME\n");
for(int i=0;i<numberofprocess;i++)
{
printf("P[%d] %d %d %d %d\n",nm[i],bt[i],priority[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);
}