sfjnp.c

 avatar
unknown
plain_text
a year ago
971 B
3
Indexable
#include <stdio.h>
void main(){
float bt[20];
float at[20];
float wt[20];
float tat[20];
int n;
float completion_time =0;
float total_waiting_time =0;
float total_turnaround_time =0;

float lat = 0;
printf("Enter the number of process: ");
scanf("%d",&n);

for (int i =0; i< n; i++){
printf("process %d\n",i+1);
printf("Enter the arrival time: ");
scanf("%f",&at[i]);
printf("Enter the burst time: ");
scanf("%f",&bt[i]);
}
// find the least arrival time.

for (int i =1 ; i< n ; i++){
lat = at[0];
if (at[i] <= lat ){
lat = at[i];
}
}

completion_time = lat;
for (int i =0; i< n; i++){


completion_time += bt[i];
tat[i] = completion_time - at[i];
wt[i] = tat[i] - bt[i];

total_turnaround_time += tat[i];
total_waiting_time += wt[i];

}

printf("Total tat : %f\n", total_turnaround_time);
printf("Total wt: %f\n", total_waiting_time);

printf("Average turnaround time : %f\n", total_turnaround_time / n);
printf("Average waiting time : %f\n", total_waiting_time / n);
}
Editor is loading...
Leave a Comment