0% found this document useful (0 votes)
2 views2 pages

fcfs code

The document contains a C program that calculates the 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, sorts them by arrival time, and computes the completion time, turnaround time, and waiting time. Finally, it outputs the results 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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

fcfs code

The document contains a C program that calculates the 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, sorts them by arrival time, and computes the completion time, turnaround time, and waiting time. Finally, it outputs the results 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 PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

int main()

int n, i;

int at[20], bt[20], ct[20], tat[20], wt[20];

float avg_tat = 0, avg_wt = 0;

printf("Enter number of processes: ");

scanf("%d", &n);

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

printf("Enter Arrival Time and Burst Time for Process %d: ", i + 1);

scanf("%d%d", &at[i], &bt[i]);

for (i = 0; i < n - 1; i++)

for (int j = i + 1; j < n; j++)

if (at[i] > at[j])

int temp = at[i];

at[i] = at[j];

at[j] = tem

temp = bt[i];

bt[i] = bt[j];

bt[j] = temp;

}
}

ct[0] = at[0] + bt[0];

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

if (at[i] > ct[i - 1])

ct[i] = at[i] + bt[i];

else

ct[i] = ct[i - 1] + bt[i];

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

tat[i] = ct[i] - at[i];

wt[i] = tat[i] - bt[i];

avg_tat += tat[i];

avg_wt += wt[i];

printf("\nP\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("\nAverage Turnaround Time = %.2f", avg_tat / n);

printf("\nAverage Waiting Time = %.2f\n", avg_wt / n);

return 0;

You might also like