Search This Blog

Friday, November 25, 2011

SJF SCHEDULING ALGORITHM IN C

#include<stdio.h>
#include<conio.h>
#include<process.h>
int main()
{
char temp[5];
int tot=0,wt[10],bt[10],i,j,n,temp1;
int avg=0;

printf("enter no of processes:");
scanf("%d",&n);
printf("enter burst time");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(bt[i]>bt[j])
{
temp1=bt[i];
bt[i]=bt[j];
bt[j]=temp1;

}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tot=tot+wt[i];
}
avg=tot/n;
printf("total waiting time=%d\n avg waiting time=%d",tot,avg);
getch();
}

No comments:

Post a Comment