FCFS Scheduling - Code Explanation
#include <stdio.h>
Includes the standard input/output library. Needed to use printf and scanf.
void main() {
Main function of the program. We use void main() in Turbo C.
int n, i; int bt[20], wt[20], tat[20]; float avg_wt = 0, avg_tat = 0;
Declares variables:
- n: number of processes
- bt: burst times
- wt: waiting times
- tat: turnaround times
- avg_wt and avg_tat to store totals for average calculation.
Input for burst times
Takes burst time for each process using a loop. Uses scanf to read user input.
wt[0] = 0;
Waiting time for the first process is always zero in FCFS scheduling.
Calculating waiting time
Each process's waiting time = previous waiting time + previous burst time.
Calculating turnaround time and averages
Turnaround time = burst time + waiting time. We also calculate the total waiting and turnaround times to
compute averages.
Printing the result
Prints a table showing each processs Burst Time, Waiting Time, and Turnaround Time.
Printing averages
Displays the average waiting and turnaround times at the end.