Skip to content

Planet-Source-Code/adri-jovin-round-robin-scheduling__3-11772

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Round Robin Scheduling

Description

This program simulates the Round Robin Scheduling Algorithm.

More Info

Submitted On
By Adri Jovin
Level Advanced
User Rating 4.6 (23 globes from 5 users)
Compatibility C
Category Algorithms
World C / C++
Archive File

Source Code

//Source code produced by Adri Jovin.J.J
#include<stdio.h>
main()
{
int pt[10][10],a[10][10],at[10],pname[10][10],i,j,n,k=0,q,sum=0;
float avg;
printf("\n\nEnter the number of processes : ");
scanf("%d",&n);
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
pt[i][j]=0;
a[i][j]=0;
}
}
for(i=0;i<n;i++)
{
j=0;
printf("\n\nEnter the process time for process %d: ",i+1);
scanf("%d",&pt[i][j]);
}
printf("\n\nEnter the time slice : ");
scanf("%d",&q);
printf("\n\n");
for(j=0;j<10;j++)
{
for(i=0;i<n;i++)
{
a[2*j][i]=k;
if((pt[i][j]<=q)&&(pt[i][j]!=0))
{
pt[i][j+1]=0;
printf("%d P%d %d\n",k,i+1,k+pt[i][j]);
k+=pt[i][j];
a[2*j+1][i]=k;
}
else if(pt[i][j]!=0)
{
pt[i][j+1]=pt[i][j]-q;
printf(" %d P%d %d\n",k,i+1,(k+q));
k+=q;
a[2*j+1][i]=k;
}
else
{
a[2*j][i]=0;
a[2*j+1][i]=0;
}
}
}
for(i=0;i<n;i++)
{
sum+=a[0][i];
}
for(i=0;i<n;i++)
{
for(j=1;j<10;j++)
{
if((a[j][i]!=0)&&(a[j+1][i]!=0)&&((j+1)%2==0))
{
sum+=((a[j+1][i]-a[j][i]));
}
}
}
avg=(float)sum/n;
printf("\n\nAverage waiting time= %f msec",avg);
sum=avg=0;
for(j=0;j<n;j++)
{
i=1;
while(a[i][j]!=0)
{
i+=1;
}
sum+=a[i-1][j];
}
avg=(float)sum/n;
printf("\n\n Average turnaround time =%f msec\n\n",avg);
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published