Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int i,j,n,time,sum_wait=0,sum_turnaround=0,smallest;
  5. int at[10],bt[10],pt[10],rt[10],remain; //rt = remaining Time
  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",&pt[i]);
  15. rt[i]=bt[i];
  16. }
  17. pt[9]=11;
  18. printf("\n\nProcess\t|Turnaround time|waiting time\n");
  19. for(time=0;remain!=0;time++)
  20. {
  21. smallest=9;
  22. for(i=0;i<n;i++)
  23. {
  24. if(at[i]<=time && pt[i]<pt[smallest] && rt[i]>0)
  25. {
  26. smallest=i;
  27. }
  28. }
  29. rt[smallest]--;
  30. if(rt[smallest]==0)
  31. {
  32. remain--;
  33. printf("P[%d]\t|\t%d\t|\t%d\n",smallest+1,time+1-at[smallest],time+1-at[smallest]-bt[smallest]);
  34. sum_wait+=time+1-at[smallest];
  35. sum_turnaround+=time+1-at[smallest]-bt[smallest];
  36. }
  37. }
  38. printf("\nAvg waiting time = %f\n",sum_wait*1.0/n);
  39. printf("Avg turnaround time = %f",sum_turnaround*1.0/n);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement