-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityScheduling.c
70 lines (58 loc) · 1.55 KB
/
PriorityScheduling.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>
#include <conio.h>
#include <dos.h>
int main()
{
int n, b[10], w[10], i, j, h, t, tt;
int stime[10], a[10], p[10];
float avg = 0;
printf("\n\tPRIORITY SCHEDULING ALGORITHM");
printf("\n\t*****************************************************\n");
printf("\nEnter howmany jobs:");
scanf("%d", &n);
printf("\nEnter burst time & priority for corresponding job....\n");
for (i = 1; i <= n; i++)
{
printf("\nProcess %d:", i);
scanf("%d %d", &b[i], &p[i]);
a[i] = i;
}
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++)
if (p[i] < p[j])
{
t = b[i];
tt = a[i];
b[i] = b[j];
a[i] = a[j];
b[j] = t;
a[j] = tt;
}
w[1] = 0;
printf("\nprocess %d waiting time is 0", a[1]);
for (i = 2; i <= n; i++)
{
w[i] = b[i - 1] + w[i - 1];
printf("\nProcess %d waiting time: %d", a[i], w[i]);
avg += w[i];
}
printf("\ntotal waiting time:%f", avg);
printf("\n\nthe average waiting time is:%f\n", avg / n);
printf("\nGaunt Chart\n***************************************\n\n\t");
h = 22;
for (i = 1; i <= n; i++)
{
printf("%d", b[i]);
for (j = 1; j <= b[i]; j++)
printf("%c", h);
}
printf("\n\t");
for (i = 1; i <= n; i++)
{
printf("%d", w[i]);
for (j = 1; j <= w[i]; j++)
printf("%c", h);
delay(1000);
}
getch();
}