program for sjf algoritham using c


SJF ALGORITHM
#include<stdio.h>
main()
{
int job[10],i,j,n,t,s[10],wt[10];
float sum=0.0;
printf("\nEnter no of jobs");
scanf("%d",&n);
printf("Enter burst time");
for(i=0;i<n;i++)
{
scanf("%d",&job[i]);
s[job[i]]=i;
}
for(i=0;i<n;i++)
for(j=0;j<n-(i+1);j++)
if(job[j]>job[j+1])
{
t=job[j];
job[j]=job[j+1];
job[j+1]=t;
}
printf("\nJOB\tEXECUTION TIME\t WAITING TIME\t TURN AROUND TIME");
for(i=0;i<n;i++)
{
sum+=job[i];
wt[i]=sum-job[i];
printf("\n%d\t%d\t\t%d\t\t%f",s[job[i]],job[i],wt[i],sum);
}
printf("\nmean time=%f",sum/n);
}

















No comments:

Post a Comment