#include <stdio.
h>
int main()
int n, i;
int at[20], bt[20], ct[20], tat[20], wt[20];
float avg_tat = 0, avg_wt = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
printf("Enter Arrival Time and Burst Time for Process %d: ", i + 1);
scanf("%d%d", &at[i], &bt[i]);
for (i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (at[i] > at[j])
int temp = at[i];
at[i] = at[j];
at[j] = tem
temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
}
}
ct[0] = at[0] + bt[0];
for (i = 1; i < n; i++) {
if (at[i] > ct[i - 1])
ct[i] = at[i] + bt[i];
else
ct[i] = ct[i - 1] + bt[i];
for (i = 0; i < n; i++) {
tat[i] = ct[i] - at[i];
wt[i] = tat[i] - bt[i];
avg_tat += tat[i];
avg_wt += wt[i];
printf("\nP\tAT\tBT\tCT\tTAT\tWT\n");
for (i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t%d\t%d\t%d\n", i + 1, at[i], bt[i], ct[i], tat[i], wt[i]);
printf("\nAverage Turnaround Time = %.2f", avg_tat / n);
printf("\nAverage Waiting Time = %.2f\n", avg_wt / n);
return 0;