Thursday, February 3, 2011

SHORTEST JOB FIRST SCHEDULING PROGRAM

PROGRAM SOURCE CODE
# include<stdio.h>
main()
{
int k=0,ptime[25],n,s=0,I,sum=0;
char name[25][25];
int t,p,time[10],pao[10];
float avg;
printf (“enter the no. of process: \t”);
scanf (“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter the name for processes: \t”);
printf(“%d \t”,i+1);
scanf(“%s”,name[i]);
}
printf(“\n \n”);

for(i=0;i<n;i++)
{
printf(“enter the process time: \t”);
printf(“%s \t”,name[i]);
scanf(“%d”,&ptime[i]);
}
printf(“\n \n”);
printf(“\n process – name \t process – time \n”);
for(i=0;i<n;i++)
{
printf(“\t %s \t \t %d \n”,name[i],ptime[i]);
}
printf(“\n \n SJF SCHEDULING \n \n”);
for(i=0;i<n;i++)
{
pas[i]=i;
time[i]=ptime[i];
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(time[i]>time[j])
{
p=time[i];
time[i]=time[j];
time[j]=p;
t=pas[i];
pas[i]=pas[j];
pas[j]=t;
}
}
}


for(i=0;i<n;i++)
{
printf(“process %s from %d to %d \n”,name[pas[i],k,(k+time[i]);
k+=time[i];
}
for(i=0;i<(n-1);i++)
{
s+=time[i];
sum+=s;
}
avg=(float)sum/n;
printf(“\n\n average waiting time: \t”);
printf(“%2fmsec”,avg);
sum=avg=s=0;
for(i=0;i<n;i++)
{
s+=ptime[i];
sum+=s;
}
avg=(float)sum/n;
printf(“\n turn around time is \t”);
printf(“%2fmsec”,avg);
}

No comments:

Post a Comment