Round Robin Problem #include<stdio.h>
#include<conio.h>
int main()
{
int p[30],p1[30],g[30],t,bt[30],wt[30],ta[30],sum=0,i,j,n,sw=0,sb=0,k=0;
float temp=0,max=0;
g[0]=0;
printf("enter the number of processes=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nenter the burst time of process p%d=",i+1);
scanf("%d",&bt[i]);
p[i]=bt[i];
}
printf("Enter the size of time slice--");
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);j++)
{
for(i=0;i<n;i++)
{
if(bt[i]!=0)
{
if(bt[i]<=t)
{
ta[i]=temp+bt[i];
temp=temp+bt[i];
g[k+1]=g[k]+bt[i];
bt[i]=0;
}
else
{
bt[i]=bt[i]-t;
temp=temp+t;
g[k+1]=g[k]+t;
}
p1[k]=i+1;
k++;
}
}
}
for(i=0;i<n;i++)
{
wt[i]=ta[i]-p[i];
sum+=ta[i];
sw+=wt[i];
sb+=p[i];
}
printf("\nROUND ROBIN SCHEDULING ALGORITHM\n");
printf("--------------------------------");
printf("\n Process\tBurst time(ms)\t\t Waiting Time(ms)\t
TurnAround Time(ms)\n\n");
for(i=0;i<n;i++)
{
printf(" P%d\t\t\t%d\t\t\t%d\t\t\t%d\n",i+1,p[i],wt[i],ta[i]);
}
printf("\n\nGantt Chart:\n\n");
for(i=0;i<k;i++)
{
printf(" P%d",p1[i]);
}
printf("\n 0");
for(i=1;i<=k;i++)
{
printf(" %d",g[i]);
}
printf("\n\nAverage Waiting…