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

FCFS

The document contains a C program that calculates the waiting time and turnaround time for a set of processes based on their burst times. It defines a structure for processes and includes functions to compute average waiting and turnaround times. The program prompts the user to input the number of processes and their respective burst times, then displays the results.

Uploaded by

gdrivealts
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

FCFS

The document contains a C program that calculates the waiting time and turnaround time for a set of processes based on their burst times. It defines a structure for processes and includes functions to compute average waiting and turnaround times. The program prompts the user to input the number of processes and their respective burst times, then displays the results.

Uploaded by

gdrivealts
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

struct Process {
int pid; // Process ID
int burst_time; // Burst Time
int waiting_time; // Waiting Time
int turnaround_time; // Turnaround Time
};

void findWaitingTime(struct Process proc[], int n) {


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

for (int i = 1; i < n; i++) {


proc[i].waiting_time = proc[i - 1].waiting_time + proc[i - 1].burst_time;
}
}

void findTurnaroundTime(struct Process proc[], int n) {


for (int i = 0; i < n; i++) {
proc[i].turnaround_time = proc[i].burst_time + proc[i].waiting_time;
}
}

void findAverageTime(struct Process proc[], int n) {


int total_wt = 0, total_tat = 0;

findWaitingTime(proc, n);
findTurnaroundTime(proc, n);

printf("\nProcesses Burst time Waiting time Turnaround time\n");

for (int i = 0; i < n; i++) {


total_wt += proc[i].waiting_time;
total_tat += proc[i].turnaround_time;
printf(" %d ", proc[i].pid);
printf(" %d ", proc[i].burst_time);
printf(" %d ", proc[i].waiting_time);
printf(" %d\n", proc[i].turnaround_time);
}

printf("\nAverage waiting time = %.2f", (float)total_wt / (float)n);


printf("\nAverage turnaround time = %.2f\n", (float)total_tat / (float)n);
}

int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);

struct Process proc[n];


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

for (int i = 0; i < n; i++) {


proc[i].pid = i + 1;
printf("Process %d: ", i + 1);
scanf("%d", &proc[i].burst_time);
}

findAverageTime(proc, n);
return 0;
}

You might also like