#include<stdio.h>
#include<conio.h>
int main()
{
int i ,j,waiting[3],last[3],lefttime[3],burst[3];
float awt=0.0;
int gap=0;
int sum=0;
printf("\n\t Enter the process information");
for(i=0;i<3;i++)
{
fflush(stdin);
printf("\n\n\t Process %d",i+1);
printf("\n\n Enter Burst Time:");
scanf("%d",&burst[i]);
waiting[i]=0;
lefttime[i]=0;
last[i]=0;
}
printf("\n\n Enter the interval time:");
scanf("%d",&gap);
printf("\n\n gap=%d", gap);
for(i=0;i<3;i++)
{
sum=sum+burst[i];
}
printf("\n\n sum=%d", sum);
for(i=0;i<3;i++)
{
lefttime[i]=burst[i];
}
j=0;
i=0;
while(1)
{
if(lefttime[j]>0)
{
if(lefttime[j]<=gap)
{
waiting[j]=waiting[j]+(i-last[j]);
i=i+lefttime[j];
last[j]=i+lefttime[j];
lefttime[j]=0;
}
else if(lefttime[j]>gap)
{
waiting[j]=waiting[j]+(i-last[j]);
i=i+gap;
last[j]=i;
lefttime[j]=lefttime[j]-gap;
}
}
if(i>=sum)
break;
if(j==2)
j=0;
else
j++;
}
for(i=0;i<3;i++)
{
printf("\n\nWaiting time for p%d = %d",i+1,waiting[i]);
awt=awt+waiting[i];
}
awt=awt/3.0;
printf("\n\n\t Hence the Average waiting time =%.3f",awt);
getch();
return 0;
}
Gurpreet Singh
No comments:
Post a Comment