-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr.c
More file actions
53 lines (39 loc) · 1.09 KB
/
Copy pathpr.c
File metadata and controls
53 lines (39 loc) · 1.09 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
#include <stdio.h>
int main() {
int n, p[100], tat[100], bt[100], wt[100], pr[100];
printf("Enter the number of process : ");
scanf("%d", &n);
printf("Enter the burst time and priority\n");
for(int i = 0; i < n; i++) {
scanf("%d%d", &bt[i], &pr[i]);
p[i] = i + 1;
}
// sorting based on priority
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(pr[i] > pr[j]) {
int temp = pr[i];
pr[i] = pr[j];
pr[j] = temp;
temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
wt[0] = 0;
for(int i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
}
for(int i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
}
printf("\nProcess\tBurst\tPriority\tWait\tTat\n");
for(int i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t\t%d\t%d\n", p[i], bt[i], pr[i], wt[i], tat[i]);
}
return 0;
}