0% found this document useful (0 votes)
7 views1 page

1) Fcfs

This C program calculates and displays the completion time, turnaround time, and waiting time for a set of processes based on their arrival and burst times. It prompts the user to input the number of processes and their respective arrival and burst times, then computes the necessary times and averages. Finally, it prints the results in a formatted table along with the average turnaround and waiting times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

1) Fcfs

This C program calculates and displays the completion time, turnaround time, and waiting time for a set of processes based on their arrival and burst times. It prompts the user to input the number of processes and their respective arrival and burst times, then computes the necessary times and averages. Finally, it prints the results in a formatted table along with the average turnaround and waiting times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main() {
int n, at[10], bt[10], wt[10], tat[10], ct[10], sum, i, j;
float total_tat = 0, total_wt = 0;

printf("Enter the no of processes:\n");


scanf("%d", &n);

for(i = 0; i < n; i++) {


printf("Enter at[%d]: ", i);
scanf("%d", &at[i]);
printf("Enter bt[%d]: ", i);
scanf("%d", &bt[i]);
}

// Completion Time
sum = at[0];
for(j = 0; j < n; j++) {
sum += bt[j];
ct[j] = sum;
}

// Turn Around Time


for(i = 0; i < n; i++) {
tat[i] = ct[i] - at[i];
total_tat += tat[i];
}

// Waiting Time
for(i = 0; i < n; i++) {
wt[i] = tat[i] - bt[i];
total_wt += wt[i];
}

// Display
printf("\nProcess\tAT\tBT\tCT\tTAT\tWT\n");
for(i = 0; i < n; i++) {
printf("P%d\t%d\t%d\t%d\t%d\t%d\n", i+1, at[i], bt[i], ct[i], tat[i],
wt[i]);
}

printf("\nAvg TAT: %.2f\n", total_tat / n);


printf("Avg WT : %.2f\n", total_wt / n);

return 0;
}

You might also like