#include<stdio.h>
void main()
{
int p[5],b[5],i,j,temp=0,w=0,t=0,wt=0,tt=0;
float ATT,AWT;
printf("\n\n\tSJF SCHEDULING ALGORITHM\n");
printf("\n\tEnter The Burst Time For 5 Processs:\n");
for(i=1;i<=5;i++)
{
printf("\n\tEnter The Burst Time For Process P%d: ",i);
scanf("%d",&b[i]);
p[i]=i;
}
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
printf("\n\n\tPRO\tBT\tWT\tTT\n");
printf("===========================================================\n");
{
for(i=1;i<=5;i++)
{
t=w+b[i];
printf("\n\n\tP%d\t%d\t%d\t%d",p[i],b[i],w,t);
tt=tt+t;
wt=wt+w;
w=w+b[i];
}
printf("\n\n\tTotal Waiting Time: %d ",wt);
printf("\n\tTotal T-Time: %d ",tt);
}
AWT=wt/5;
ATT=tt/5;
printf("\n\n\tAverage Waiting Time: %f ",AWT);
printf("\n\tAverage T-Time: %f \n\n",ATT);
}
void main()
{
int p[5],b[5],i,j,temp=0,w=0,t=0,wt=0,tt=0;
float ATT,AWT;
printf("\n\n\tSJF SCHEDULING ALGORITHM\n");
printf("\n\tEnter The Burst Time For 5 Processs:\n");
for(i=1;i<=5;i++)
{
printf("\n\tEnter The Burst Time For Process P%d: ",i);
scanf("%d",&b[i]);
p[i]=i;
}
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
printf("\n\n\tPRO\tBT\tWT\tTT\n");
printf("===========================================================\n");
{
for(i=1;i<=5;i++)
{
t=w+b[i];
printf("\n\n\tP%d\t%d\t%d\t%d",p[i],b[i],w,t);
tt=tt+t;
wt=wt+w;
w=w+b[i];
}
printf("\n\n\tTotal Waiting Time: %d ",wt);
printf("\n\tTotal T-Time: %d ",tt);
}
AWT=wt/5;
ATT=tt/5;
printf("\n\n\tAverage Waiting Time: %f ",AWT);
printf("\n\tAverage T-Time: %f \n\n",ATT);
}
No comments:
Post a Comment