Assignmente 2
Assignmente 2
#include <stdio.h>
int main() {
int n;
findAverageTime(processes, n, burst_time);
return 0;
}
Output
Enter the number of processes: 5
Enter burst time for each process:
Process 1: 4
Process 2: 3
Process 3: 1
Process 4: 2
Process 5: 5
Processes Burst Time Waiting Time Turnaround Time
1 4 0 4
2 3 4 7
3 1 7 8
4 2 8 10
5 5 10 15
sortProcessesByBurstTime(processes, n, bt);
int main() {
int n;
findAverageTime(processes, n, burst_time);
return 0;
}
Output
Enter the number of processes: 5
Enter burst time for each process:
Process 1: 4
Process 2: 3
Process 3: 1
Process 4: 2
Process 5: 5
Processes Burst Time Waiting Time Turnaround Time
3 1 0 1
4 2 1 3
2 3 3 6
1 4 6 10
5 5 10 15
● Round Robin
#include <stdio.h>
int time = 0;
while (1) {
int done = 1;
if (done == 1) {
break; }
}
}
int main() {
int n, quantum;
return 0;
}
Output
Enter the number of processes: 3
Enter burst time for each process:
Process 1: 4
Process 2: 3
Process 3: 3
Enter time quantum: 4
Processes Burst Time Waiting Time Turnaround Time
1 4 0 4
2 3 4 7
3 3 7 10
Average Waiting Time: 3.67
Average Turnaround Time: 7.00
#include <stdio.h>
int time = 0;
if (min_priority_index != -1) {
wt[min_priority_index] = time;
time += bt[min_priority_index];
completed[min_priority_index] = 1;
}
}
}
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
return 0;
}
Output
Enter the number of processes: 5
Enter burst time and priority for each process:
Process 1:
Burst Time: 10
Priority: 3
Process 2:
Burst Time: 1
Priority: 1
Process 3:
Burst Time: 2
Priority: 4
Process 4:
Burst Time: 1
Priority: 5
Process 5:
Burst Time: 5
Priority: 2
Processes Burst Time Priority Waiting Time Turnaround Time
1 10 3 6 16
2 1 1 0 1
3 2 4 16 18
4 1 5 18 19
5 5 2 1 6
#include <stdio.h>
#include <stdbool.h>
scheduling
void findWaitingTime(int processes[], int n, int bt[], int wt[], int
priority[], int quantum) {
int remaining_bt[n];
bool completed[n];
int time = 0;
if (!process_found) {
bool all_completed = true;
for (int i = 0; i < n; i++) {
if (!completed[i]) {
all_completed = false;
break;
}
}
if (all_completed) break;
}
}
}
int main() {
int n, quantum;
return 0;
}
Output
Enter the number of processes: 4
Enter burst time and priority for each process:
Process 1:
Burst Time: 8
Priority: 2
Process 2:
Burst Time: 4
Priority: 1
Process 3:
Burst Time: 9
Priority: 2
Process 4:
Burst Time: 5
Priority: 3
Enter time quantum: 3