fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6. int i, NOP, sum=0, count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];
  7. float avg_wt, avg_tat;
  8.  
  9. printf("Total number of processes in the system: ");
  10. scanf("%d", &NOP);
  11. y = NOP;
  12.  
  13. for(i=0; i<NOP; i++)
  14. {
  15. printf("\nEnter Arrival and Burst time of Process[%d]\n", i+1);
  16. printf("Arrival time: ");
  17. scanf("%d", &at[i]);
  18. printf("Burst time: ");
  19. scanf("%d", &bt[i]);
  20. temp[i] = bt[i];
  21. }
  22.  
  23. printf("Enter the Time Quantum: ");
  24. scanf("%d", &quant);
  25.  
  26. printf("\nProcess No \tBurst Time \tTAT \tWaiting Time ");
  27. for(sum=0, i=0; y!=0; )
  28. {
  29. if(temp[i] <= quant && temp[i] > 0)
  30. {
  31. sum += temp[i];
  32. temp[i] = 0;
  33. count = 1;
  34. }
  35. else if(temp[i] > 0)
  36. {
  37. temp[i] -= quant;
  38. sum += quant;
  39. }
  40. if(temp[i]==0 && count==1)
  41. {
  42. y--;
  43. printf("\nP[%d]\t\t%d\t\t%d\t\t%d", i+1, bt[i], sum-at[i], sum-at[i]-bt[i]);
  44. wt += sum - at[i] - bt[i];
  45. tat += sum - at[i];
  46. count = 0;
  47. }
  48. if(i == NOP - 1)
  49. i = 0;
  50. else if(at[i+1] <= sum)
  51. i++;
  52. else
  53. i = 0;
  54. }
  55.  
  56. avg_wt = (float)wt / NOP;
  57. avg_tat = (float)tat / NOP;
  58. printf("\nAverage Turn Around Time: %f", avg_tat);
  59. printf("\nAverage Waiting Time: %f\n", avg_wt);
  60. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Total number of processes in the system: Enter the Time Quantum: 
Process No 	Burst Time 	TAT 	Waiting Time 
Average Turn Around Time: -nan
Average Waiting Time: -nan