#include <stdio.h> int main(void) { int n, at[10], bt[10], ct[10], tat[10], wt[10], sum, i, j, k; float totaltat = 0, totalwt = 0; // Prompt user to enter the number of processors printf("Enter No of processors: "); scanf("%d", &n); // Input the arrival times of each processor for(i = 0; i < n; i++) { printf("Enter the arrival time of processor %d: ", i + 1); scanf("%d", &at[i]); } // Input the burst times of each processor for(i = 0; i < n; i++) { printf("Enter the burst time of processor %d: ", i + 1); scanf("%d", &bt[i]); } // Initialization of the first sum to the arrival time of the first process sum = at[0]; // Calculation of completion times for each processor for(j = 0; j < n; j++) { sum = sum + bt[j]; // Increment sum by the burst time ct[j] = sum; // Set completion time for the current process } // Calculation of turn around time for(k = 0; k < n; k++) { tat[k] = ct[k] - at[k]; // Turnaround time is completion time minus arrival time totaltat = totaltat + tat[k]; // Accumulate total turnaround time } // Calculation of waiting time for(i = 0; i < n; i++) { wt[i] = tat[i] - bt[i]; // Waiting time is turnaround time minus burst time totalwt = totalwt + wt[i]; // Accumulate total waiting time } // Print the results printf("Process\tAT\tBT\tCT\tTAT\tWT\n"); for(i = 0; i < n; i++) { printf("\nP%d\t%d\t%d\t%d\t%d\t%d\t\n", i + 1, at[i], bt[i], ct[i], tat[i], wt[i]); } // Print average turnaround time and average waiting time printf("average of turn around time: %0.1f\n", totaltat / n); printf("average of waiting time: %0.1f\n", totalwt / 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