SHORTEST JOB FIRST
#include<stdio.h>#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char p[10][10],t[10];
printf("enter the no, of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process name,arrival time,execution time:");
scanf("%s%d%d",p[i],&at[i],&et[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(et[i]<et[j])
{
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],t);
}
}
for(i=0;i<n;i++)
{
if(i==0)
st[i]=at[i];
else
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
totwt=wt[i];
totta=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("\nname\tat\tbt\twt\ttat\tft");
for(i=0;i<n;i++)
printf("\n%s\t%d\t%d\t%d\t%d\t%d",p[i],at[i],et[i],wt[i],ta[i],ft[i]);
printf("\nAverage waiting time=%f",awt);
printf("\nAverage turnaround time=%f",ata);
}
No comments:
Post a Comment