0% found this document useful (0 votes)
6 views

FCFS1 C

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)
6 views

FCFS1 C

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>
#include <conio.h>

void main() {
int n, i, j;
int bt[20], wt[20], tat[20];
float avg_wt = 0, avg_tat = 0;

clrscr();

printf("Enter the number of processes: ");


scanf("%d", &n);

printf("Enter Burst Time for each process:\n");


for (i = 0; i < n; i++) {
printf("Process %d: ", i + 1);
scanf("%d", &bt[i]);
}

// Calculate Waiting Time


wt[0] = 0; // Waiting time for first process is 0
for (i = 1; i < n; i++) {
wt[i] = wt[i - 1] + bt[i - 1];
}

// Calculate Turnaround Time


for (i = 0; i < n; i++) {
tat[i] = wt[i] + bt[i];
}

// Calculate average waiting time and turnaround time


for (i = 0; i < n; i++) {
avg_wt += wt[i];
avg_tat += tat[i];
}
avg_wt /= n;
avg_tat /= n;

// Display results
printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (i = 0; i < n; i++) {
printf("%d\t\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i], tat[i]);
}

printf("\nAverage Waiting Time: %.2f", avg_wt);


printf("\nAverage Turnaround Time: %.2f", avg_tat);

getch();
}

You might also like