Facebook
From adii, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 152
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct sjf
  4. {
  5. int pid;
  6. int btime;
  7. int ttime;
  8. int wtime;
  9.  
  10. }
  11. P[10];
  12. int main()
  13. {
  14. int i,j,n;
  15. struct sjf temp;
  16. int totwtime=0,tottime=0;
  17. printf ("scheduling\n");
  18. printf("enter the no.of process");
  19. scanf("%d",&n);
  20. for(i=0;i<n;i++)
  21. {
  22. for(j=i+1;j<n;j++)
  23. {
  24. if(P[i].btime>P[j].btime)
  25. {
  26. temp=P[i];
  27. P[i]=P[j];
  28. P[j]=temp;
  29. }
  30. }
  31. }
  32. for(i=0;i<n;i++)
  33. {
  34. P[i].wtime=P[i-1].wtime=P[i-1].btime;
  35. P[i].ttime=P[i].wtime+P[i].btime;
  36. tottime=tottime+P[i].ttime;
  37. totwtime=totwtime+P[i].wtime;
  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.