ROUND ROBIN ALGORITHM
#include<stdio.h>
main()
{
int a[20],b[20],c[20],i,j=0,n,d,bt=0,count,time,p,e;
clrscr();
printf("\nEnter no of jobs");
scanf("%d",&n);
printf("Enter burst time");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("Enter processing time");
scanf("%d",&time);
p=a[1];
for(i=1;i<=n;i++)
if(p<a[i])
p=a[i];
count=p/time+1;
while(count>0)
{
count--;
for(i=1;i<=n;i++)
if(a[i]>0)
{
if(a[i]>time)
{
d=time;
e=i;
a[i]=a[i]-time;
}
else
{
d=a[i];
e=i;
a[i]=a[i]-a[i];
}
j++;
b[j]=e;
c[j]=d;
}
}
printf("\nThe processing sequence is\n");
for(i=1;i<=j;i++)
printf("p%d ",b[i]);
printf("\n");
for(i=1;i<=j;i++)
printf("%2d",c[i]);
printf("\n");
for(i=1;i<=j;i++)
{
bt=bt+c[i];
}
printf("\nTotal burst time=%d",bt);
}
No comments:
Post a Comment