Shishu

shortest job first of operating system in c

Sep 19th, 2018
215
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.  
  6.     int bt[20], wt[20], tat[20], i, n,p[20],temp=0,k;
  7.     float wtavg, tatavg;
  8.     printf ("Enter the no. of process: ");
  9.     scanf("%d",&n);
  10.     for(i=0; i<n; i++)
  11.     {
  12.         p[i]=i;
  13.         printf ("Enter burst time for processed %d:",i);
  14.         scanf ("%d", &bt[i]);
  15.     }
  16.     for(i=0; i<n;i++)
  17.     {
  18.  
  19.         for(k=i+1; k<n;k++)
  20.         {
  21.             if(bt[i]>bt[k])
  22.             {
  23.                 temp=bt[i];
  24.                 bt[i]=bt[k];
  25.                 bt[k]=temp;
  26.  
  27.                 temp=p[i];
  28.                 p[i]=p[k];
  29.                 p[k]=temp;
  30.             }
  31.         }
  32.     }
  33.  
  34.  
  35.     //waiting time & TA time
  36.     wt[0]=0;
  37.     tat[0]=bt[0];
  38.  
  39.     for(i=1; i<n; i++)
  40.     {
  41.         wt[i]=tat[i-1];
  42.         tat[i]=bt[i]+wt[i];
  43.     }
  44.        printf("\t process \t Bust time \t waiting time \t turnarandT");
  45.     for(i=0; i<n; i++)
  46.     {
  47.         printf("\n\t p%d   \t\t%d \t\t%d \t\t%d",p[i],bt[i],wt[i],tat[i]);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment