Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
887 B
1
Indexable
Never
#include<stdio.h>
#include<conio.h>
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq,i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
printf("number of process:");
scanf("%d",&n);
printf("Enter burst time squence:");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
printf("enter time quantum:");
scanf("%d",&tq);
}
while(1)
{
for(i=0,count=0;i<n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq+=temp;
tat[i]=sq;
}
if(n==count)
break;
for(i=0;i<n;i++)
{
wt[i]=tat[i]-bt[i];
swt+=wt[i];
stat+=tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no\tBurst time\twait time\tTurn around time\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("Avg wait time is %f\nAvg turn around time is %f",awt,atat);
}
}
}