C program – Shortest Job Next

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




 #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();
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings.
  2. C program to input real numbers and find the mean, variance and standard deviation
  3. C program to accept a set of numbers and compute mean, variance and standard deviation
  4. C program to accept the height of a person in centimeter and categorize the person based on height as taller, dwarf and average height person
  5. C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers. And display the results

Leave a Comment

Previous post:

Next post: