You are on page 1of 2

/* w.a.

p on shortest job first sheduling algorithm */


#include<stdio.h>
#include<conio.h>
void sort(int bt[10],int );
void main()
{
int n,bt[10],wt[10],tot[10],i;
float awt=0,atot=0;
clrscr();
printf("\n enter the no of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n p[%d]: ",i);
scanf("%d",&bt[i]);
}
sort(bt,n);
for(i=0;i<n;i++)
{
if(i==0)
{
wt[i]=0;
tot[i]=bt[i];
}
else
{
wt[i]=wt[i-1]+bt[i-1];
tot[i]=(tot[i-1]+bt[i]);
}
awt +=wt[i];;
atot +=tot[i];
}
awt=awt/n;
awt=atot/n;
printf("\n average waiting time is %f",awt);
printf("\n average turn around time is %f",atot);
getch();
}
void sort(int bt[10],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(bt[j]>bt[j+1])
{
temp=bt[j];
bt[j]=bt[j+1];
bt[j+1]=temp;
}
}
}
}
Output:
enter no of process : 3
p[0] :6
p[1] :3
p[0] :7
average waiting time is 9.333
average turn around time is 28.000

You might also like