Wednesday, March 9, 2016

Shortest Job First(Operating System)

//Created by "Arunendra Kumar"//
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,j,t,n,smallest,temp,sum=0,total=0;
float avg;
clrscr();
printf("\n\t\t\tScheduling program of SJF\n\n");
printf("\nEnter the no of jobs : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the burst time for %d process : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
smallest=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[smallest])
{
smallest=j;
}
}
temp=a[i];
a[i]=a[smallest];
a[smallest]=temp;
}
printf("\nProcesses are :\n\n");
printf("Process no  \t\tBurst time\n");
for(i=0;i<n;i++)
{
printf("%d\t\t\t\t%d\n",i+1,sum);
sum=sum+a[i];
}
sum=0;
for(i=0;i<n-1;i++)
{
sum=sum+a[i];
total=total+sum;
}
avg=total/(float)n;
printf("\nTotal burst time is: %d microseconds",total);
printf("\nAvarage burst time is: %f microseconds",avg);
getch();
}

No comments:

Post a Comment