#include <stdio.h>
int main() {
int n, i;
int bt[20], wt[20], tat[20];
int total_wt = 0, total_tat = 0;
printf("Enter the number of processes: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Enter burst time for Process %d: ", i + 1);
scanf("%d", &bt[i]);
}
wt[0] = 0;
for (i = 1; i < n; i++) {
wt[i] = bt[i - 1] + wt[i - 1];
}
printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
printf("P%d\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i], tat[i]);
}
, printf("\nAverage Waiting Time: %.2f", (float)total_wt / n);
printf("\nAverage Turnaround Time: %.2f\n", (float)total_tat / n);
return 0;
}
Enter the number of processes: 3
Enter burst time for Process 1: 5
Enter burst time for Process 2: 3
Enter burst time for Process 3: 8
Process Burst Time Waiting Time Turnaround Time
P1 5 0 5
P2 3 5 8
P3 8 8 16
Average Waiting Time: 4.33
Average Turnaround Time: 9.67
Priority Scheduling in C
#include <stdio.h>
int main() {
int n, i, j;
int bt[20], p[20], pt[20], wt[20], tat[20];
int total_wt = 0, total_tat = 0;
printf("Enter the number of processes: ");
scanf("%d", &n);