DATE: 06/10/2020
waiting[smallest] = end - a[smallest] - x[smallest]
turnaround[smallest] = end - a[smallest]
#include<stdio.h>
int main(){
int a[10], b[10], x[10], pr[10] = {0};
int waiting[10], turnaround[10], completion[10];
int i, j, smallest, count = 0, time, n;
float avg = 0, tt = 0, end;
printf("\\nEnter total number of Processes: ");
scanf("%d", & n);
printf("Enter arrival time of process:\\n");
for (i = 0; i < n; i++) {
printf("p(%d):", i + 1);
scanf("%d", & a[i]);
}
printf("Enter burst time of process:\\n");
for (i = 0; i < n; i++) {
printf("p(%d):", i + 1);
scanf("%d", & b[i]);
}
printf("Enter priority of process:\\n");
for (i = 0; i < n; i++) {
printf("p(%d):", i + 1);
scanf("%d", & pr[i]);
}
for (i = 0; i < n; i++) x[i] = b[i];
pr[9] = -1;
for (time = 0; count != n; time++) {
smallest = 9;
for (i = 0; i < n; i++) {
if (a[i] <= time && pr[i] > pr[smallest] && b[i] > 0) smallest = i;
}
time += b[smallest] - 1;
b[smallest] = -1;
count++;
end = time + 1;
completion[smallest] = end;
waiting[smallest] = end - a[smallest] - x[smallest];
turnaround[smallest] = end - a[smallest];
}
printf("\\nPid Arrival Burst Priority Complete Waiting Turn\\n");
for (i = 0; i < n; i++) {
printf("\\np%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %
d\\ n ",i+1,a[i],x[i],pr[i],completion[i],waiting[i],turnaround[i]); avg = avg + waiting[i];
tt = tt + turnaround[i];
}
printf("Average waiting time =%f \\n", avg / n);
printf("Average Turnaround time =%f \\n", tt / n);
}