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