Thursday, 23 October 2014

C code for shortest job first cpu scheduling algorithm

#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();

 int i,j,n,temp,totalwt=0;
 int btime[5];
 int wtime[5];
 wtime[0]=0;
 printf("enter the no of process");
 scanf("%d",&n);

 for(i=0;i<n;i++)
 {
   printf("enter the process %d brust time",i+1);
   scanf("%d",&btime[i]);
 }


 for(i=0;i<n;i++)
 {
   for(j=i+1;j<n;j++)
   {
     if(btime[i]>btime[j])
     {
     temp=btime[i];
     btime[i]=btime[j];
     btime[j]=temp;
     }
   }
 }





for(i=1;i<=n;i++)
{
 wtime[i]=wtime[i-1]+btime[i-1];
 totalwt=totalwt+wtime[i];
 }

printf("total waiting time=%d",totalwt);
printf("average waiting time=%f",totalwt/n);



getch();
}

No comments:

Post a Comment