6. Write a program to calculates Waiting Time (WT), Turnaround Time (TAT), Average WT, and Average TAT using the FCFS (First Come First Serve) scheduling algorithm.

 #include <stdio.h>


int main() {

    float burst_time[30], waiting_time[30], turn_around_time[30];

    float average_waiting_time = 0.0, average_turnaround_time = 0.0;

    int count, j, total_process;


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

    scanf("%d", &total_process);


    printf("Enter the burst time of each process:\n");

    for (count = 0; count < total_process; count++) {

        printf("Process [%d]: ", count + 1);

        scanf("%f", &burst_time[count]);

    }


    waiting_time[0] = 0; // First process has 0 waiting time


    // Calculate waiting time for each process

    for (count = 1; count < total_process; count++) {

        waiting_time[count] = 0;

        for (j = 0; j < count; j++) {

            waiting_time[count] += burst_time[j];

        }

    }


    // Calculate turnaround time and average times

    printf("\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n");

    for (count = 0; count < total_process; count++) {

        turn_around_time[count] = burst_time[count] + waiting_time[count];

        average_waiting_time += waiting_time[count];

        average_turnaround_time += turn_around_time[count];


        printf("P[%d]\t%.2f\t\t%.2f\t\t%.2f\n", count + 1, burst_time[count], waiting_time[count], turn_around_time[count]);

    }


    average_waiting_time /= total_process;

    average_turnaround_time /= total_process;


    printf("\nAverage Waiting Time = %.6f", average_waiting_time);

    printf("\nAverage Turnaround Time = %.6f\n", average_turnaround_time);


    return 0;

}

Comments

Popular posts from this blog

8. To write a program in C to calculate waiting time, turn around time and average waiting time when non preemptive SJF is used

7. C Program: Preemptive SJF Scheduling (WT, TAT, AWT)