#include<stdio.h>
int main()
{
int
p[10],bt[10],wt[10],n,key,tmp,i,j;
floatawt=0.0,awt2=0.0;
printf("Enter the no. of
processes: ");
scanf("%d",&n);
printf("Enter the burst
times\n");
for(i=0;i<n;i++)
{
p[i]= i+1;
scanf("%d",&bt[i]);
}
wt[0]=0,tmp=0;
for(i=0;i<n;i++)
{
awt += tmp;
tmp += bt[i];
wt[i+1]= tmp;
printf("\nWaiting time of
process %d is %d \n turn around time= %d ",i,wt[i],wt[i+1]);
}
awt/=n;
printf("Average waiting
time for FCFS = %.3f\n",awt);
tmp=0;
for(i=1;i<n;i++)
{key=bt[i];
tmp=p[i];
for(j=i-1;j>=0
&&bt[j]>key ; j--)
{
bt[j+1]=bt[j];
p[j+1]=p[j];
}
bt[j+1]=key;
p[j+1]=tmp;
}
tmp=0,wt[0]=0;
for(i=0;i<n;i++)
{
awt2 += tmp;
tmp += bt[i];
wt[i+1]= tmp;
printf("\nWaiting time of
process %d is %d \n turn around time= %d ",i,wt[i],wt[i+1]);
}
awt2 /= n;
printf("Average waiting
time for SJF= %.3f\n",awt2);
if(awt<awt2)
printf("For the given
processes, FCFS is better than SJF since %f<%f", awt,awt2);
else
printf("For the given
processes, SJF is better than FCFS since %f>%f", awt,awt2);
return 0;
}
No comments:
Post a Comment