0% found this document useful (0 votes)
35 views2 pages

Round Robin

This code implements a round robin scheduling algorithm. It takes as input the number of processes, time quantum, and burst times of each process. It then calculates the waiting time and turnaround time for each process based on the round robin scheduling. The waiting time and turnaround time are then printed along with the original burst times.
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)
35 views2 pages

Round Robin

This code implements a round robin scheduling algorithm. It takes as input the number of processes, time quantum, and burst times of each process. It then calculates the waiting time and turnaround time for each process based on the round robin scheduling. The waiting time and turnaround time are then printed along with the original burst times.
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/ 2

ROUND ROBIN

CODE:
#include<stdio.h>

int main()

int n,i,j,c,a[100],b[100],d[100],t;

printf("Enter no.of processes and time quantum\n");

scanf("%d%d",&n,&t);

printf("Enter the burst times\n");

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

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

if(a[i]>t) b[i]=a[i]/t;

else b[i]=0;}

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

if(a[i]>t)

{c=0;

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

if(j!=i){

if(b[j]==0) c=c+a[j];

else if(i<j&&b[j]>0){

if(b[j]<b[i]) c=c+a[j];

else if(b[j]==b[i]) {

if(a[i]%t==0) c=c+(b[i]-1)*t;

else c=c+b[i]*t;}

else { if(a[i]%t==0) c=c+(b[i]-1)*t;

else c=c+(b[i])*t;}

else if(i>j&&b[j]>0){
if(b[j]<b[i]) c=c+a[j];

else if(b[j]==b[i]) c=c+a[j];

else { if(a[i]%t==0) c=c+b[i]*t;

else c=c+(b[i]+1)*t;}}

}}

d[i]=c; }

else{

if(i==0) d[i]=0;

else {c=0;

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

if(a[j]>t) c=c+t;

else c=c+a[j];}

}d[i]=c;}}

printf("burst_time waiting_time turn_around_time\n");

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

printf("%d %d %d\n",a[i],d[i],a[i]+d[i]);

}INPUT AND OUTPUT:


Enter no.of processes and time quantum
3
3
Enter the burst times
24
3
6
burst_time waiting_time turn_around_time
24 9 33
3 3 6
6 9 15

You might also like