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(); }
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
June 1st, 2010 at 6:17 pm
// 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();
}
October 12th, 2010 at 7:25 am
Priyanka@: that program was already edited ?i mean it will run sir>
October 25th, 2010 at 7:18 pm
sir this is static could u give me dynamic program for round robbin
February 20th, 2011 at 9:15 pm
#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();
}