Advertisement
Tusohian

Shortest Job First (SJF)

Sep 19th, 2018
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void main()
  4. {
  5.     int bt[20], wt[20], tat[20], i, n, p[20], temp=0, k;
  6.     float wtavg, tatavg, watag;
  7.     printf ("Enter the no. of process: ");
  8.     scanf("%d",&n);
  9.     for(i=0; i<n; i++)
  10.     {
  11.         p[i]=i;
  12.         printf ("Enter burst time for process %d: ", i);
  13.         scanf ("%d", &bt[i]);
  14.     }
  15.  
  16.     for (i=0; i<n; i++)
  17.     {
  18.         for(k=i+1; k<n; k++)
  19.         {
  20.             if(bt[i]>bt[k])
  21.             {
  22.                 temp=bt[i];
  23.                 bt[i]=bt[k];
  24.                 bt[k]=temp;
  25.  
  26.                 temp=p[i];
  27.                 p[i]=p[k];
  28.                 p[k]=temp;
  29.             }
  30.         }
  31.     }
  32.  
  33.  
  34.  
  35.     wt[0] = 0;
  36.     tat[0] = bt[0];
  37.  
  38.     for(i=0; i<=n; i++)
  39.     {
  40.         wt[i]=tat[i-1];
  41.         tat[i]= wt[i]+bt[i];
  42.     }
  43.  
  44.  
  45.  
  46.     printf("\t Process \t Burst Time \t Waiting Time \t TurnaroundT");
  47.  
  48.     for(i=0; i<n; i++)
  49.     {
  50.         printf("\n\t p%d \t\t%d \t\t%d \t\t%d", p[i], bt[i], wt[i], tat[i]);
  51.     }
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement