Advertisement
souravchwn

Untitled

Dec 7th, 2020
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,i,j,pid[10],bt[10],wt[10],tat[10],total_wt,total_tat,pos,temp,total=0;
  5.     float avg_wt, avg_tat;
  6.     printf("Enter the Size: ");
  7.     scanf("%d",&n);
  8.     printf("\nEnter the burst time: ");
  9.  
  10.     for(i=0; i<n; i++)
  11.     {
  12.         scanf("%d",&bt[i]);
  13.         pid[i]=i;
  14.     }
  15.     for(i=0; i<n; i++)
  16.     {
  17.         pos=i;
  18.         for(j=i+1; j<n; j++)
  19.         {
  20.             if(bt[j]<bt[pos])
  21.                 pos=j;
  22.         }
  23.  
  24.         temp=bt[i];
  25.         bt[i]=bt[pos];
  26.         bt[pos]=temp;
  27.         temp=pid[i];
  28.         pid[i]=pid[pos];
  29.         pid[pos]=temp;
  30.     }
  31.     wt[0]=0;
  32.     for(i=1; i<n; i++)
  33.     {
  34.         wt[i]=0;
  35.         for(j=0; j<i; j++)
  36.             wt[i]+=bt[j];
  37.         total+=wt[i];
  38.     }
  39.     avg_wt=(float)total/n;
  40.     total=0;
  41.     printf("\nProcess \t Burst T \tWaiting T \tTurnaround T");
  42.     for(i=0; i<n; i++)
  43.     {
  44.         tat[i]=bt[i]+wt[i];
  45.         total+=tat[i];
  46.         printf("\np%\d\t\t %d\t\t %d\t\t\t%d",pid[i],bt[i],wt[i],tat[i]);
  47.     }
  48.     avg_tat=(float)total/n;
  49.     printf("\n\nAverage waiting Time= %f",avg_wt);
  50.     printf("\nAverage turnaround Time= %f\n",avg_tat);
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement