#include<stdio.h>
#include<conio.h>
int b[15],t[15],z[15],w[15];
int i,j,n,q,max,rr,e;
main()
{
printf("ROUND ROBIN Job Scheduling Algo");
printf("\n*******************************");
printf("\n\nEnter the no. of processes:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
w[i]=0;
}
printf("Enter the burst times of the processes \n");
for(i=1;i<=n;i++)
{
printf("process %d:",i);
scanf("%d",&b[i]); z[i]=b[i];
}
printf("Enter the time slice:");
scanf("%d",&q);
int round(void);
round();
getch();
return 0;
}
int round()
{
e=0;
max=b[1];
for(i=2;i<n;i++)
if(max<=b[i])
max=b[i];
if(max%q==0)
rr=max/q;
else
rr=max/q+1;
for(i=1;i<=rr;i++)
{
printf("Round %d:",i);
for(j=1;j<=n;j++)
{
if(b[j]>0)
{
b[j]=b[j]-q;
if(b[j]>0)
{
printf("\nprocess %d, time remaining %d",j,b[j]);
e=e+q;
}
else
{
e=e+b[j]+q;
b[j]=0;
printf("\nprocess %d is completed",j);
}
t[j]=e;
}
}
printf("\n\n\n");
}
for(i=1;i<=n;i++)
{
w[i]=t[i]-z[i];
}
printf("\nP\t\tb-t\t\tw-t\t\ttr-t");//process,burst time,waiting time,turn around time
for(i=1;i<=n;i++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d",i,z[i],w[i],t[i]);
}
getch();
return 0;
}