Advertisement
Tusohian

Shortest Job First (SJF) - with 1 line swap

Sep 19th, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 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], 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.  
  23.                 (bt[i] ^= bt[k]), (bt[k] ^= bt[i]), (bt[i] ^= bt[k]);
  24.  
  25.                 (p[i] ^= p[k]), (p[k] ^= p[i]), (p[i] ^= p[k]);
  26.  
  27.             }
  28.         }
  29.     }
  30.  
  31.  
  32.  
  33.     wt[0] = 0;
  34.     tat[0] = bt[0];
  35.  
  36.     for(i=0; i<=n; i++)
  37.     {
  38.         wt[i]=tat[i-1];
  39.         tat[i]= wt[i]+bt[i];
  40.     }
  41.  
  42.  
  43.  
  44.     printf("\t Process \t Burst Time \t Waiting Time \t TurnaroundT");
  45.  
  46.     for(i=0; i<n; i++)
  47.     {
  48.         printf("\n\t p%d \t\t%d \t\t%d \t\t%d", p[i], bt[i], wt[i], tat[i]);
  49.     }
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement