Loading…
OS · CPU scheduling · Program 15 · In the record
Write A Program in c to implement the FCFS Algorithm
1#include <stdio.h>2 3int main()4{5 int n, i;6 int bt[20], wt[20], tat[20];7 float total_wt = 0, total_tat = 0;8 9 printf("Enter number of processes: ");10 scanf("%d", &n);11 12 printf("Enter burst time for each process:\n");13 for (i = 0; i < n; i++)14 {15 printf("P%d: ", i + 1);16 scanf("%d", &bt[i]);17 }18 19 // First process does not wait20 wt[0] = 0;21 22 // Each process waits for all the ones before it23 for (i = 1; i < n; i++)24 wt[i] = wt[i - 1] + bt[i - 1];25 26 for (i = 0; i < n; i++)27 {28 tat[i] = wt[i] + bt[i];29 total_wt += wt[i];30 total_tat += tat[i];31 }32 33 printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");34 for (i = 0; i < n; i++)35 printf("P%d\t%d\t\t%d\t\t%d\n", i + 1, bt[i], wt[i], tat[i]);36 37 printf("\nAverage Waiting Time = %.2f\n", total_wt / n);38 printf("Average Turnaround Time = %.2f\n", total_tat / n);39 40 return 0;41}3 ⏎ 5 ⏎ 3 ⏎ 8Enter number of processes: 3 Enter burst time for each process: P1: 5 P2: 3 P3: 8 Process Burst Time Waiting Time Turnaround Time P1 5 0 5 P2 3 5 8 P3 8 8 16 Average Waiting Time = 4.33 Average Turnaround Time = 9.67
Run program 15 in your browser
bash · just-bash. Change the code or the input, run it, break it, and see what happens.