C Program to show an example of Round Robin Scheduling
#include<stdio.h>
void main()
{
int i,n,k,s=0,r=0,q=0,x=0,a[30],e[30],t[30],w[30];
float m,p=0;
printf("Enter the number of processes:");
scanf("%d",&n);
printf("Enter the execution time:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
e[i]=a[i];
}
printf("Enter the quantum time:");
scanf("%d",&q);
printf("After the r r scheduling:");
while(s<=k)
{
for(i=0;i<n;i++)
{
if(a[i]>0)
{
if(a[i]>q)
{
r=r+q;
a[i]=a[i]-q;
printf("P%d\t",i+1);
}
else
{
r=r+a[i];
a[i]=a[i]-q;
printf("P%d\t",i+1);
t[i]=r;
w[i]=t[i]-e[i];
}
}
}
s++;
}
printf("\nProcess\tBurst Time\tWaiting Time\tTurn Around Time\n");
int tt=0,wt=0;
for(i=0;i<n;i++)
{
printf("%d\t\t%d\t\t%d\t\t%d\t\t\n",i+1,e[i],w[i],t[i]);
tt=tt+t[i];
wt=wt+w[i];
}
printf("Average waiting time:%d\n",wt/n);
printf("Average turn around time:%d\n",tt/n);
}
Comments
Post a Comment