fork download
  1.  
  2. #include <stdio.h>
  3. int main(){
  4. int p[10],at[10],bt[10],ct[10],tat[10],wt[10],i,j,temp=0,n;
  5. float awt=0,atat=0;
  6. printf("enter no of process:\n");
  7. scanf("%d",&n);
  8. printf("Enter processes:\n");
  9. for(i=0;i<n;i++){
  10. scanf("%d",&p[i]);
  11. }
  12. printf("Enter arrival time of each process:\n");
  13. for(i=0;i<n;i++){
  14. scanf("%d",&at[i]);
  15. }
  16. printf("Enter burst time for each processes:\n");
  17. for(i=0;i<n;i++){
  18. scanf("%d",&bt[i]);
  19. }
  20. for(i=0;i<n;i++){
  21. for(j=0;j<n;j++){
  22. if(at[j]>at[j+1]){
  23. temp=p[j+1];
  24. p[j+1]=p[j];
  25. p[j]=temp;
  26. temp=at[j+1];
  27. at[j+1]=at[j];
  28. at[j]=temp;
  29. temp=bt[j+1];
  30. bt[j+1]=bt[j];
  31. bt[j]=temp;
  32. }
  33. }
  34. }\
  35. ct[0]=at[0]+bt[0];
  36. for(i=1;i<n;i++){
  37. if(ct[i-1]<at[i]){
  38. temp=at[i]-ct[i-1];
  39. }
  40. ct[i]=bt[i]+ct[i-1]+temp;
  41. }
  42. printf("\n p\t AT\t BT\t CT\t TAT\t WT\t");
  43. for(i=0;i<n;i++){
  44. tat[i]=ct[i]-at[i];
  45. wt[i]=tat[i]-bt[i];
  46. atat+=tat[i];
  47. awt+=wt[i];
  48. }
  49. atat=atat/n;
  50. awt=awt/n;
  51. for(i=0;i<n;i++){
  52. printf("\n P%d\t %d\t %d\t %d\t %d\t %d",p[i],at[i],bt[i],ct[i],tat[i],wt[i]);
  53. }
  54. printf("avg tuen around time=%d",atat);
  55. printf("avg waiting time =%d",awt);
  56. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
1 2 3
24 3 3
stdout
enter no of process:
Enter processes:
Enter arrival time of each process:
Enter burst time for each processes:

 p	 AT	 BT	 CT	 TAT	 WT	
 P0	 0	 32765	 32765	 32765	 0
 P2	 3	 32765	 98295	 98292	 65527
 P3	 3	 1519044224	 1519175284	 1519175281	 131057avg tuen around time=131057avg waiting time =0