Advertisement
Tusohian

Round Rabin Alogrithm

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