C program for Shortest Job Next

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

C program for Shortest Job Next

 #include<stdio.h>
 #include<conio.h>
 #include<math.h>
 void main()
 {
   int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20];
   float avgw,avgt;
   clrscr();
   printf("\n Enter no.of job:");
   scanf("%d",&n);
   printf("enter the job:");
   for(i=1;i<=n;i++)
    {
      scanf("%d",&b[i]);
      x[i]=i;
    }
   for(i=1;i<=n-1;i++)
   {
    for(j=i+1;j<=n;j++)
    {
      if(b[i]>b[j])
      {
        temp=b[i];
        b[i]=b[j];
        b[j]=temp;
        s=x[i];
        x[i]=x[j];
        x[j]=s;
      }
   }
 }
   c=0;
   d=0;
   for(i=1;i<=n;i++)
    {
       w[i]=w[i-1]+b[i-1];
       t[i]=b[i]+t[i-1];
       w[1]=0;
       t[1]=b[1];
       c+=w[i];
       d+=t[i];
    }
  avgw=(float)c/n;
  avgt=(float)d/n;
 printf("job \t waiting time \t service time \t turn around time \t \n :");
 for(i=1;i<=n;i++)
  {
     printf("%d \t %d \t ",x[i],b[i]);
     printf("%d \t %d \t",w[i],t[i]);
     printf("\n");
  }
     printf("average wait time %f \n",avgw);
     printf("average turn around %f \n",avgt);
     getch();
}

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

2 Responses to “C program for Shortest Job Next”

  1. please post the shortest job first program using structure.
    thank you

    Reply

Leave a Reply