Facebook
From hh, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 140
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct sjf{
  4. int pid;
  5. int btime;
  6. int wtime;
  7. int ttime;
  8. }P[10];
  9.  
  10. int main()
  11. {
  12. int i,n,j;
  13. struct sjf tmp;
  14. int totwtime=0,tottime=0;
  15.  
  16. printf("Enter no of Processes \n");
  17. scanf("%d",&n);
  18. for(i=0;i<n-1;i++)
  19.  {
  20.   for(j=i+1;j<n;j++)
  21.    {
  22.     if(P[i].btime>P[j].btime)
  23.      {
  24.       tmp=P[i];
  25.       P[i]=P[j];
  26.       P[i]=tmp;
  27.      }
  28.    }
  29.  }
  30. for(i=0;i<n;i++)
  31.  {
  32.   P[i].wtime=P[i-1].wtime+P[i-1].btime;
  33.   P[i].ttime=P[i].wtime+P[i].btime;
  34.  
  35.   tottime = tottime+P[i].ttime;
  36.   totwtime = totwtime+P[i].wtime;
  37.  }
  38.  
  39. printf("Total Waiting time: %d \n",totwtime);
  40. printf("Average Waiting time: %d \n", totwtime/n);
  41. printf("Total turnaround time: %d \n", tottime);
  42. printf("Average turnaround time: %d \n", tottime/n);
  43.  
  44. }