Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int st[10],bt[10],wt[10],tat[10],n,tq;
  6. int i,count=0,swt=0,stat=0,temp,sq=0;
  7. float awt=0.0,atat=0.0;
  8. clrscr();
  9. printf("Enter number of processes:");
  10. scanf("%d",&n);
  11. printf("Enter burst time for sequences:");
  12. for(i=0;i<n;i++)
  13. {
  14. scanf("%d",&bt[i]);
  15. st[i]=bt[i];
  16. }
  17. printf("Enter time quantum:");
  18. scanf("%d",&tq);
  19. while(1)
  20. {
  21. for(i=0,count=0;i<n;i++)
  22. {
  23. temp=tq;
  24. if(st[i]==0)
  25. {
  26. count++;
  27. continue;
  28. }
  29. if(st[i]>tq)
  30. st[i]=st[i]-tq;
  31. else
  32. if(st[i]>=0)
  33. {
  34. temp=st[i];
  35. st[i]=0;
  36. }
  37. sq=sq+temp;
  38. tat[i]=sq;
  39. }
  40. if(n==count)
  41. break;
  42. }
  43. for(i=0;i<n;i++)
  44. {
  45. wt[i]=tat[i]-bt[i];
  46. swt=swt+wt[i];
  47. stat=stat+tat[i];
  48. }
  49. awt=(float)swt/n;
  50. atat=(float)stat/n;
  51. printf("Process_no Burst time Wait time Turn around time
  52. ");
  53. for(i=0;i<n;i++)
  54. printf("%d %d %d %d
  55. ",i+1,bt[i],wt[i],tat[i]);
  56. printf("Avg wait time is %f
  57. Avg turn around time is %f",awt,atat);
  58. getch();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement