#include<stdio.
h>
int main(){
int n, i;
printf("\nEnter process count : ");
scanf("%d",&n);
int BT[n], AT[n], P[n], CT[n], TAT[n], WT[n], completed[n];
float total_WT = 0, total_TAT = 0, avg_WT, avg_TAT;
printf("\nEnter Burst times : ");
for(i = 0; i<n; i++){
scanf("%d",&BT[i]);
printf("\nEnter Arrive times : ");
for(i = 0; i<n; i++){
scanf("%d",&AT[i]);
printf("\nEnter priorities : ");
for(i = 0; i<n; i++){
scanf("%d",&P[i]);
for(i=0; i<n; i++){
completed[i] = 0;
int curr_time = 0;
int completed_count = 0;
while(completed_count < n){
int index = -1;
int highest_priority = 100; //comparision value for priority
for(i = 0; i<n; i++){
if(AT[i] <= curr_time && !completed[i] && P[i] < highest_priority){
highest_priority = P[i];
index = i;
if(index == -1){
curr_time++;
continue;
curr_time += BT[index];
CT[index] = curr_time;
completed[index] = 1;
completed_count++;
for(i = 0; i<n; i++){
TAT[i] = CT[i] - AT[i];
WT[i] = TAT[i] - BT[i];
for(i = 0; i<n; i++){
total_WT += WT[i];
total_TAT += TAT[i];
avg_WT = total_WT / n;
avg_TAT = total_TAT / n;
printf("\nProcess\tBT\tAT\tPrio\tCT\tTAT\tWT\n");
for(i = 0; i<n; i++){
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", i+1, BT[i], AT[i], P[i], CT[i],
TAT[i], WT[i]);
printf("\n\nAverage waiting time is %.2f",avg_WT);
printf("\nAverage turnaround time is %.2f",avg_TAT);
return 0;
}
Enter process count : 5
Enter Burst times : 10
Enter Arrive times : 0
Enter priorities : 3
Process BT AT Prio CT TAT WT
1 10 0 3 16 16 6
2 1 0 1 1 1 0
3 2 0 4 18 18 16
4 1 0 5 19 19 18
5 5 0 2 6 6 1
Average waiting time is 8.20
Average turnaround time is 12.00