Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Thursday, 16 November 2017

C Program To implement Round Robin Scheduling

         C  Program To implement Round Robin Scheduling


#include<stdio.h>

int n,b[10],b1[10],c[10]={0},t[10]={0},w[10]={0},c1[100],p1[100],p[10];
void disp()
{
int i;
printf(" \npid\t burst \t wait \t completion \n ");
for(i=0;i<n;i++)
{
printf("\n%d\t%d\t%d\t%d",p[i],b[i],w[i],c[i]);
}
}
main()
{int i,j,s=0,k=0,q,x=0;
printf(" eneter no of procesese");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter BURST TIME ");
p[i]=i+1;
scanf("%d",&b[i]);
b1[i]=b[i];
}
printf(" enter time quantum");
scanf("%d",&q);
disp();
for(i=0;s!=n;i++)
{
if(i==n)
i=0;
if(b1[i]==0)
{
s++;
}
else{
if(b1[i]<=q)
{
x=(c1[k]=x+b1[i]);
b1[i]=0;
s++;
} else
{
b1[i]-=q;
s=0;
x=(c1[k]=x+q);
}
p1[k]=p[i];
k++;}}
for(j=0;j<k;j++)
{
printf("\ncompletion time %d \tprocessid %d",c1[j],p1[j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<k;j++)
{
if(p1[j]==i+1)
{
c[i]=c1[j];
}
}
w[i]=c[i]-b[i]; }
disp();
}


No comments:

Post a Comment