Tuesday, April 13, 2010

Round Robin

#include
#include
void main()
{
int b[10],i,j=1,n,temp,burst[10],wait[10],turn[10],p[10],a=1,q,tat[10],t1=0;
float t=0,w=0;
clrscr();
printf("enter the no of process & Quantum time");
scanf("%d%d",&n,&q);
burst[0]=0;
b[0]=0;
tat[0]=0;
p[0]=0;
printf("enter burst time");
for(i=1;i<=n;i++)
scanf("%d",&burst[i]);
for(i=1;i<=n;i++)
b[i]=burst[i];
printf("\n\n\t\t gantt chart\n");
printf("_________________________________________________________\n");
for(i=1;i<=n;i++)
{
if(b[i]>0)
{
a=1;
printf("P%d\t|",i);
if(b[i]>=q)
{
t1=t1+q;
p[j]=t1;
j++;
}
else if(b[i]
{
t1=t1+b[i];
p[j]=t1;
j++;
}
b[i]=b[i]-q;
if(b[i]<=0)
tat[i]=t1;
}
else
a++;
if(a==n+1)
break;
if(i==n)
i=0;
}
printf("\n_________________________________________________________\n\n");
for(i=0;i
printf("%d\t",p[i]);
for(i=1;i<=n;i++)
{
t=t+tat[i];
w=w+tat[i]-burst[i];
}
w=w/n;
t=t/n;
printf("\n\n the average waiting time is %0.2f",w);
printf("\n\n the average turn around turnaround time is %0.2f",t);
getch();
}
/*Output:
enter the no of process & Quantum time3 4
enter burst time18 3 3                                                         
                                                                               

                 gantt chart                                                   
____________________________________                   
P1      |P2     |P3     |P1     |P1     |P1     |P1     |                      
____________________________________                  
                                                                               
0       4       7       10        14      18      22      24                     
                                                                               
 the average waiting time is 5.67                                              
                                                                               
 the average turn around turnaround time is 13.67
 */

1 comments:

Anonymous said...

some condition is missing in if, & for loop i not complete

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase