#include void findWaitingTime(int n, int bt[], int wt[], int at[], int pr[]) { int rt[n]; // Copying burst time into remaining time for (int i = 0; i < n; i++) { rt[i] = bt[i]; } int complete = 0; int t = 0; int minPriorityIndex; int currentProcess = -1; int flag = 0; int tempMinPriority; while (complete != n) { // Finding process with highest priority among arrived processes minPriorityIndex = -1; tempMinPriority = 1000000; for (int i = 0; i < n; i++) { if (at[i] <= t && rt[i] > 0 && pr[i] < tempMinPriority) { minPriorityIndex = i; tempMinPriority = pr[i]; } } if (minPriorityIndex == -1) { t++; continue; } if (currentProcess != minPriorityIndex) { currentProcess = minPriorityIndex; wt[minPriorityIndex] = t - at[minPriorityIndex]; } rt[minPriorityIndex]--; if (rt[minPriorityIndex] == 0) { complete++; flag = 0; t++; } else { flag = 1; t++; } } } void findTurnAroundTime(int n, int bt[], int wt[], int tat[]) { for (int i = 0; i < n; i++) { tat[i] = bt[i] + wt[i]; } } void findAverageTime(int n, int bt[], int at[], int pr[]) { int wt[n], tat[n], total_wt = 0, total_tat = 0; findWaitingTime(n, bt, wt, at, pr); findTurnAroundTime(n, bt, wt, tat); printf("Process Arrival Time Burst Time Priority Waiting Time Turn-Around Time\n"); for (int i = 0; i < n; i++) { total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; printf(" P%d\t\t%d\t %d\t\t%d\t\t%d\t\t%d\n", i+1, at[i], bt[i], pr[i], wt[i], tat[i]); } printf("\nAverage waiting time = %f", (float)total_wt / (float)n); printf("\nAverage turn-around time = %f\n", (float)total_tat / (float)n); } int main() { int n; printf("Enter the number of processes: "); scanf("%d", &n); int bt[n], at[n], pr[n]; for (int i = 0; i < n; i++) { printf("\nEnter Arrival Time, Burst Time and Priority for Process %d: ", i+1); scanf("%d%d%d", &at[i], &bt[i], &pr[i]); } findAverageTime(n, bt, at, pr); return 0; }