0% found this document useful (0 votes)
24 views5 pages

Round Robin

Uploaded by

O'levels Academy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

Round Robin

Uploaded by

O'levels Academy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ROUND ROBIN

#include<stdio.h>

int main(){

int i, j, n, bt[10], wt[10], tat[10], t, ct[10], max;

float awt = 0, att = 0, temp=0;

printf("Enter the no of processes\n");

scanf("%d",&n);

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

printf("\nEnter Burst Time for process %d\n ", i+1);

scanf("%d", &bt[i]);

ct[i] = bt[i];

printf("\nEnter the size of time slice\n");

scanf("%d",&t);

max = bt[0];

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

if(max < bt[i]){

max = bt[i];

for(j = 0; j < (max/t)+1; j++)

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

if(bt[i] != 0)

if(bt[i] <= t){


tat[i] = temp + bt[i];

temp = temp + bt[i];

bt[i] = 0;

else{

bt[i] = bt[i] - t;

temp = temp + t;

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

wt[i] = tat[i] - ct[i];

att += tat[i];

awt += wt[i];

printf("\nThe Average Turnaround time is%f",att/n);

printf("\nThe Average Waiting time is %f ",awt/n);

printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUNDTIME\n");

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

printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wt[i],tat[i]);

}
PRIORITY SCHEDULING
#include<stdio.h>

void swap(int* x, int* y) {

int t = *x;

*x = *y;

*y = t;

int main() {

int n;

int p[20], pr[20], tat[20], bt[20], wt[20];

int total_wt = 0, total_tat = 0;

float avg_wt, avg_tat;

int i, j;

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


scanf("%d", &n);

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

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

printf("p[%d] ", i+1);

p[i] = i + 1; // Process number

scanf("%d %d", &bt[i], &pr[i]);

// Sorting processes based on priority (ascending)

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

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

if(pr[i] < pr[j]) {

swap(&pr[i], &pr[j]);

swap(&bt[i], &bt[j]);

swap(&p[i], &p[j]);

// Calculate waiting time for each process

wt[0] = 0; // First process doesn't wait

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

wt[i] = wt[i-1] + bt[i-1];

total_wt += wt[i];

// Calculate turnaround time for each process

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


tat[i] = wt[i] + bt[i];

total_tat += tat[i];

// Display the process information

printf("\nProcess Burst Time Waiting Time Turnaround Time\n");

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

printf("P[%d] %d %d %d\n", p[i], bt[i], wt[i], tat[i]);

// Calculate and display averages

avg_wt = (float)total_wt / n;

avg_tat = (float)total_tat / n;

printf("Average Waiting Time: %.2f\n", avg_wt);

printf("Average Turnaround Time: %.2f\n", avg_tat);

return 0; // This is the end of the main function

You might also like