fork download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n;
  5. printf("Enter number of processes: ");
  6. scanf("%d",&n);
  7. int at[n],bt[n],ct[n],tat[n],wt[n],rt[n];
  8. for(int i=0;i<n;i++)
  9. {
  10. printf("Enter the arrival and burst time for p%d : ",i+1);
  11. scanf("%d %d",&at[i],&bt[i]);
  12.  
  13. }
  14.  
  15. for(int i=0;i<n-1;i++)
  16. {
  17. for(int j=i+1;j<n;j++)
  18. {
  19. if(at[i]>at[j])
  20. {
  21. int temp;
  22. temp=at[i];at[i]=at[j];at[j]=temp;
  23. temp=bt[i];bt[i]=bt[j];bt[j]=temp;
  24. }
  25. }
  26. }
  27.  
  28. //ct
  29.  
  30. ct[0]=at[0]+bt[0];
  31. for(int i=1;i<n;i++)
  32. {
  33. if(ct[i-1]<at[i])
  34. ct[i]=at[i]+bt[i];
  35. else
  36. ct[i]=at[i-1]+bt[i];
  37. }
  38.  
  39.  
  40. //tat wt rt
  41.  
  42. for(int i=0;i<n;i++)
  43. {
  44. tat[i]=ct[i]-at[i];
  45. wt[i]=tat[i]-bt[i];
  46. rt[i]=wt[i];
  47. }
  48.  
  49. printf("\nP\tAT\tBT\tCT\tTAT\tWT\tRT\n");
  50. for(int i=0;i<n;i++)
  51. printf("P%d\t%d\t%d\t%d\t%d\t%d\t%d\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i],rt[i]);
  52. }
Success #stdin #stdout 0s 5288KB
stdin
 4
0 2
1 2
5 3
6 4
stdout
Enter number of processes: Enter the arrival and burst time for  p1 : Enter the arrival and burst time for  p2 : Enter the arrival and burst time for  p3 : Enter the arrival and burst time for  p4 : 
P	AT	BT	CT	TAT	WT	RT
P1	0	2	2	2	0	0
P2	1	2	2	1	-1	-1
P3	5	3	8	3	0	0
P4	6	4	9	3	-1	-1