ash_wath

Priority

Sep 4th, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,j,n,time,sum_wait=0,sum_turnaround=0;
  5. int smallest,at[10],bt[10],priority[10],remain;
  6. printf("Enter no of Processes : ");
  7. scanf("%d",&n);
  8. remain=n;
  9. for(i=0;i<n;i++)
  10. {
  11. printf("Enter arrival time, burst time and priority for process p%d :",i+1);
  12. scanf("%d",&at[i]);
  13. scanf("%d",&bt[i]);
  14. scanf("%d",&priority[i]);
  15. }
  16. priority[9]=11;
  17. printf("\n\nProcess\t|Turnaround time|waiting time\n");
  18. for(time=0;remain!=0;)
  19. {
  20. smallest=9;
  21. for(i=0;i<n;i++)
  22. {
  23. if(at[i]<=time && priority[i]<priority[smallest] && bt[i]>0)
  24. {
  25. smallest=i;
  26. }
  27. }
  28. time+=bt[smallest];
  29. remain--;
  30. printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time-at[smallest],time-at[smallest]-bt[smallest]);
  31. sum_wait+=time-at[smallest]-bt[smallest];
  32. sum_turnaround+=time-at[smallest];
  33. bt[smallest]=0;
  34. }
  35. printf("\nAvg waiting time = %f\n",sum_wait*1.0/n);
  36. printf("Avg turnaround time = %f",sum_turnaround*1.0/n);
  37. return 0;
  38. }
Add Comment
Please, Sign In to add comment