Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
1
Indexable
Never
#include<stdio.h>

struct Process {
    int process_id;
    int burst_time;
};

void calculateTimes(struct Process processes[], int n, int waiting_time[], int turnaround_time[]) {
    waiting_time[0] = 0;
    turnaround_time[0] = processes[0].burst_time;

    for (int i = 1; i < n; i++) {
        waiting_time[i] = turnaround_time[i - 1];
        turnaround_time[i] = waiting_time[i] + processes[i].burst_time;
    }
}

void displaySchedule(struct Process processes[], int n, int waiting_time[], int turnaround_time[]) {
    printf("Process\t Burst Time\t Waiting Time\t Turnaround Time\n");

    for (int i = 0; i < n; i++) {
        printf("%d\t\t %d\t\t %d\t\t %d\n", processes[i].process_id, processes[i].burst_time,
               waiting_time[i], turnaround_time[i]);
    }
}

int main() {
    int n;

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

    struct Process processes[n];
    int waiting_time[n], turnaround_time[n];

    for (int i = 0; i < n; i++) {
        processes[i].process_id = i + 1;
        printf("Enter burst time for process %d: ", i + 1);
        scanf("%d", &processes[i].burst_time);
    }

    calculateTimes(processes, n, waiting_time, turnaround_time);

    displaySchedule(processes, n, waiting_time, turnaround_time);

    return 0;
}
Leave a Comment