daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int bt[20],p[20],wt[20],tat[20],j,n,i,total=0,pos,temp;
  6.     float avg_wt,avg_tat;
  7.     printf("Enter number of process:");
  8.     scanf("%d",&n);
  9.  
  10.     printf("\nEnter Burst Time:\n");
  11.     for(i=0;i<n;i++)
  12.     {
  13.         printf("p%d:",i+1);
  14.         scanf("%d",&bt[i]);
  15.         p[i]=i+1;
  16.     }
  17.  
  18.  
  19.     for(i=0;i<n;i++)
  20.     {
  21.         pos=i;
  22.         for(j=i+1;j<n;j++)
  23.         {
  24.             if(bt[j]<bt[pos])
  25.                 pos=j;
  26.         }
  27.  
  28.         temp=bt[i];
  29.         bt[i]=bt[pos];
  30.         bt[pos]=temp;
  31.  
  32.         temp=p[i];
  33.         p[i]=p[pos];
  34.         p[pos]=temp;
  35.     }
  36.  
  37.     wt[0]=0;
  38.  
  39.  
  40.     for(i=1;i<n;i++)
  41.     {
  42.         wt[i]=0;
  43.         for(j=0;j<i;j++)
  44.             wt[i]+=bt[j];
  45.  
  46.         total+=wt[i];
  47.     }
  48.  
  49.     avg_wt=(float)total/n;
  50.  
  51.  
  52.     printf("\nProcess\t    Burst Time    \tWaiting Time");
  53.     for(i=0;i<n;i++)
  54.     {
  55.  
  56.         printf("\nP- %d \t\t  %d \t\t    %d\t\t",p[i],bt[i],wt[i]);
  57.     }
  58.  
  59.     avg_tat=(float)total/n;
  60.     printf("\n\nAverage Waiting Time=%f",avg_wt);
  61.  
  62.     return 0;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top