#include<stdio.
h>
int main() {
int p[10], at[10], bt[10], ct[10], tat[10], wt[10], i, j, temp = 0, n;
float awt = 0, atat = 0;
printf("Enter number of processes you want: ");
scanf("%d", &n);
printf("Enter %d processes: ", n);
for (i = 0; i < n; i++) {
scanf("%d", &p[i]);
printf("Enter %d arrival times: ", n);
for (i = 0; i < n; i++) {
scanf("%d", &at[i]);
printf("Enter %d burst times: ", n);
for (i = 0; i < n; i++) {
scanf("%d", &bt[i]);
// Sorting at, bt, and process according to at
for (i = 0; i < n; i++) {
for (j = 0; j < n - i - 1; j++) { // Fix: Corrected loop condition
if (at[j] > at[j + 1]) {
temp = p[j + 1];
p[j + 1] = p[j];
p[j] = temp;
temp = at[j + 1];
at[j + 1] = at[j];
at[j] = temp;
temp = bt[j + 1];
bt[j + 1] = bt[j];
bt[j] = temp;
// Calculating 1st ct
ct[0] = at[0] + bt[0];
// Calculating 2 to n ct
for (i = 1; i < n; i++) {
// When process is idle in between i and i+1
temp = 0;
if (ct[i - 1] < at[i]) {
temp = at[i] - ct[i - 1];
ct[i] = ct[i - 1] + bt[i] + temp;
// Calculating tat and wt
printf("\n\np\tA.T\tB.T\tC.T\tTAT\tWT");
for (i = 0; i < n; i++) {
tat[i] = ct[i] - at[i];
wt[i] = tat[i] - bt[i];
atat += tat[i];
awt += wt[i];
printf("\n%d\t%d\t%d\t%d\t%d\t%d", p[i], at[i], bt[i], ct[i], tat[i], wt[i]);
}
atat = atat / n;
awt = awt / n;
printf("\n\nAverage turnaround time is %f", atat);
printf("\nAverage waiting time is %f", awt);
return 0;