FCFS algorithm in c to find average turnaround time and waiting time

Code for FCFS Algorithm in C to Find Average Turnaround Time and Waiting Time with Explanations:

#include <stdio.h>

void findWaitingTime(int processes[], int n, int bt[], int wt[]) {
    wt[0] = 0;
    for (int i = 1; i < n; i++)
        wt[i] = bt[i - 1] + wt[i - 1];
}

void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
    for (int i = 0; i < n; i++)
        tat[i] = bt[i] + wt[i];
}

void findAvgTime(int processes[], int n, int bt[]) {
    int wt[n], tat[n];
    findWaitingTime(processes, n, bt, wt);
    findTurnAroundTime(processes, n, bt, wt, tat);

    int total_wt = 0, total_tat = 0;
    for (int i = 0; i < n; i++) {
        total_wt += wt[i];
        total_tat += tat[i];
    }

    float avg_wt = (float)total_wt / n;
    float avg_tat = (float)total_tat / n;

    printf("Average Waiting Time = %f\n", avg_wt);
    printf("Average Turnaround Time = %f\n", avg_tat);
}

int main() {
    int processes[] = {1, 2, 3};
    int n = sizeof(processes) / sizeof(processes[0]);
    int burst_time[] = {10, 5, 8};

    findAvgTime(processes, n, burst_time);

    return 0;
}

Explanation: 1. findWaitingTime function: Calculates the waiting time for each process. It initializes the waiting time for the first process as 0, and then iterates through the remaining processes to calculate their waiting time based on the burst time of the previous process and its own waiting time. 2. findTurnAroundTime function: Calculates the turnaround time for each process. It adds the burst time and waiting time to get the turnaround time for each process. 3. findAvgTime function: Combines the above two functions to find the average waiting time and average turnaround time for all processes. It then calculates the total waiting time, total turnaround time, and finally the average waiting time and average turnaround time. The results are printed to the console. 4. main function: Initializes the processes and their burst times, calculates the average time using the findAvgTime function, and prints the average waiting time and average turnaround time to the console.