Friday, 22 February 2013

Round Robin algorithm program in C

Programming Language : C

Code :
#include<stdio.h>
#include<conio.h>
int rr();


int z[10],b[10],n,m[50],r,q,e=0,avg=0,i,j;
float f;

main()
{
 clrscr();
 printf("\n\tJOB SCHEDULING ALGORITHM[Round Robin]");
 printf("\n\t*******************************************************\n");
 printf("\nEnter how many jobs:");
 scanf("%d",&n);
 printf("\nEnter burst time for corresponding job...\n");
 for(i=1;i<=n;i++)
 {
  printf("\nProcess %d: ",i);
  scanf("%d",&b[i]); z[i]=b[i];
 }

 printf("\nENTER THE TIME SLICE VALUE:");
 scanf("%d",&q);

 rr();


 getch();
 return 0;
}




rr()
{
 int max=0;
 max=b[1];
    for(j=1;j<=n;j++)
       if(max<=b[j])
    max=b[j];

 if((max%q)==0)
   r=(max/q);
 else
  r=(max/q)+1;
   for(i=1;i<=r;i++)
   {
      printf("\nround %d",i);
      for(j=1;j<=n;j++)
    {
      if(b[j]>0)
        {
         b[j]=b[j]-q;

         if(b[j]<=0)
        {
        b[j]=0;
         printf("\nprocess %d is completed",j);
        }
         else
         printf("\nprocess %d remaining time is %d",j,b[j]);
        }
     }

    }
   return 0;
}

Written by 'Shojib'.

No comments:

Post a Comment