Advertisement
Tusohian

Priority Scheduling Algorithm

Sep 26th, 2018
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 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, prio[20];
  6.     float wtavg, tatavg, watag;
  7.     printf ("Enter the no. of process: ");
  8.     scanf("%d",&n);
  9.     printf ("\n");
  10.     for(i=0; i<n; i++)
  11.     {
  12.         p[i]=i;
  13.         printf ("Enter the information for process %d : ", i);
  14.         printf ("\nEnter burst time: ");
  15.         scanf ("%d", &bt[i]);
  16.         printf ("Enter priority: ");
  17.         scanf ("%d", &prio[i]);
  18.         printf ("\n");
  19.  
  20.     }
  21.  
  22.     for (i=0; i<n; i++)
  23.     {
  24.         for(k=i+1; k<n; k++)
  25.         {
  26.             if(prio[i]>prio[k])
  27.             {
  28.  
  29.                 (prio[i] ^= prio[k]), (prio[k] ^= prio[i]), (prio[i] ^= prio[k]);
  30.  
  31.                 (bt[i] ^= bt[k]), (bt[k] ^= bt[i]), (bt[i] ^= bt[k]);
  32.  
  33.                 (p[i] ^= p[k]), (p[k] ^= p[i]), (p[i] ^= p[k]);
  34.  
  35.  
  36.             }
  37.         }
  38.     }
  39.  
  40.  
  41.  
  42.     wt[0] = 0;
  43.     tat[0] = bt[0];
  44.  
  45.     for(i=1; i<n; i++)
  46.     {
  47.         wt[i]=tat[i-1];
  48.         tat[i]= wt[i]+bt[i];
  49.     }
  50.  
  51.  
  52.  
  53.     printf("\t Process \t Priority \t Burst Time \t WT Time \t TA Time");
  54.  
  55.     for(i=0; i<n; i++)
  56.     {
  57.         printf("\n\t p%d \t\t%d \t\t%d \t\t%d \t\t%d", p[i], prio[i], bt[i], wt[i], tat[i]);
  58.     }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement