C program for Round Robin

C program for Round Robin

 
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav;
int allover()
{
for(int i=0;i<n;i++)
if(ct[i]>0)
return 0;
return 1;
}
void select(int p)
{
w[p]+=t-lat[p];
if(ct[p]>=s)
{
ct[p]-=s;
t+=s;
}
else
{
t+=ct[p];
ct[p]=0;
}
if(ct[p]==0)
ta[p]=t;
lat[p]=t;
}
void main()
{
int p=0;t=0;taav=0;wav=0;
clrscr();
printf("Enter the number of process : ");
scanf("%d",&n);
printf("\n Enter the time slice : ");
scanf("%d",&s);
printf("\nEnter the burst time of processes \n ");
for(int i=0;i<n;i++)
{
printf("\n process %d : ",i+1);
scanf("%d",&bt[i]);
ct[i]=bt[i];
lat[i]=0;
}
while(!allover())
{
if(ct[p]!=0)
select(p);
p=(p+1)%n;
}
printf("\n\n Process    Burst time   Wait time    Turn around \n\n");
for(i=0;i<n;i++)
{
printf("\n %d\t\t%d\t\t%d\t\t%d",i+1,bt[i],w[i],ta[i]);
wav+=w[i];
taav+=ta[i];
}
wav/=n;
taav/=n;
printf("\n\nAverage waiting time : %d ",wav);
printf("\n\nAverage turn around time : %d ",taav);
getch();
}
Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

9 thoughts on “C program for Round Robin

  1. // A program of round robin algorithm

    #include
    #include
    main ()
    {
    int p[10],wt[10], bt[10], tat[10], n, tq;
    int i, count = 0, twt = 0, ttat = 0, temp, sq = 0;
    float awt, atat;
    clrscr ();
    printf(“enter the no. of process=>”);
    scanf(“%d”,&n);
    printf(“\nenter process=>”);
    for(i=0;i”);
    for(i=0;i<n;i++)
    {
    scanf("%d",&bt[i]);
    p[i] = bt[i];
    }
    printf( "\n Enter time quantum : " );
    scanf ( "%d", &tq );
    while ( 1 )
    {
    for(i=0,count=0;itq )
    p[i]=p[i]-tq;
    else
    if( p[i] >= 0 )
    {
    temp = p[i];
    p[i] = 0;
    }
    sq=sq+temp;
    tat[i]=sq;
    }
    if (n==count)
    break;
    }
    for( i = 0; i < n; i++ )
    {
    wt [i] = tat[i] – bt[i];
    twt=twt+wt[i];
    ttat=ttat+tat[i];
    }
    awt =(float)twt/n;
    atat=(float)ttat/n;
    printf("p_no.\tP_bt\t p_wt\t p_tat\n" );
    for(i=0;i<n;i++)
    printf("%d\t%d\t%d\t%d\n",i+1,bt[i],wt[i],tat[i]);
    printf("total waiting time=%d\n avg waiting time=%f",twt,awt);
    printf("\ntotal turnedaroundtime=%d\n avg turnedaround time=%f",ttat, atat);
    getch();
    }

  2. #include
    #include
    #include
    int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav;
    int allover()
    {
    for(int i=0;i0)
    return 0;
    return 1;
    }
    void select(int p)
    {
    w[p]+=t-lat[p];
    if(ct[p]>=s)
    {
    ct[p]-=s;
    t+=s;
    }
    else
    {
    t+=ct[p];
    ct[p]=0;
    }
    if(ct[p]==0)
    ta[p]=t;
    lat[p]=t;
    }
    void main()
    {
    int p=0;t=0;taav=0;wav=0;
    clrscr();
    printf(“Enter the number of process : “);
    scanf(“%d”,&n);
    printf(“\n Enter the time slice : “);
    scanf(“%d”,&s);
    printf(“\nEnter the burst time of processes \n “);
    for(int i=0;i<n;i++)
    {
    printf("\n process %d : ",i+1);
    scanf("%d",&bt[i]);
    ct[i]=bt[i];
    lat[i]=0;
    }
    while(!allover())
    {
    if(ct[p]!=0)
    select(p);
    p=(p+1)%n;
    }
    printf("\n\n Process Burst time Wait time Turn around \n\n");
    for(i=0;i<n;i++)
    {
    printf("\n %d\t\t%d\t\t%d\t\t%d",i+1,bt[i],w[i],ta[i]);
    wav+=w[i];
    taav+=ta[i];
    }
    wav/=n;
    taav/=n;
    printf("\n\nAverage waiting time : %d ",wav);
    printf("\n\nAverage turn around time : %d ",taav);
    getch();
    }

  3. Thanks for your personal marvelous posting! I certainly enjoyed reading it,
    you may be a great author. I will be sure to bookmark your blog
    and will often come back at some point. I want to encourage you to ultimately continue your
    great posts, have a nice evening!

  4. If you wish for to grow your knowledge only keep
    visiting this website and be updated with the hottest news update posted here.

  5. i dont know what going here but this program is not correct for round robin scheduling… :/ this is simple calculation of waiting time and turn around time :/

  6. i dont know what is going here but this program is not correct for round robin scheduling… :/ this is simple calculation of waiting time and turn around time :/

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in