#include <stdio.h> int main() { int n; printf("Enter number of processes: "); scanf("%d", &n); int priority[n], burst[n], wait[n], turn[n]; float wt=0,tat=0; printf("Enter priority and burst times: "); for (int i = 0; i < n; i++) { scanf("%d %d", &priority[i], &burst[i]); } for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (priority[j] > priority[j+1]) { int temp = priority[j]; priority[j] = priority[j+1]; priority[j+1] = temp; temp = burst[j]; burst[j] = burst[j+1]; burst[j+1] = temp; } } } wait[0] = 0; for (int i = 1; i < n; i++) { wait[i] = wait[i - 1] + burst[i - 1]; wt+=wait[i]; } for (int i = 0; i < n; i++) { turn[i] = wait[i] + burst[i]; tat+=turn[i]; printf("Process %d: Priority %d, Burst Time %d, Waiting Time %d, Turnaround Time %d\n", i + 1, priority[i], burst[i], wait[i], turn[i]); } printf("\nthe avg wt: %.2f\n",wt/n); printf("the avg tat: %.2f\n",tat/n); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter