fork download
  1. #include<stdio.h>
  2. void main(){
  3. int i,j,n,sum,wt,tat,twt,ttat;
  4. int t[10];
  5. float awt,atat;
  6.  
  7. printf("entr no of processors:");
  8. scanf("%d\n",&n);
  9.  
  10. for(i=0;i<n;i++){
  11. printf("enter the burst time of process no %d:",i+1);
  12. scanf("%d\n",&t[i]);
  13.  
  14. }
  15. printf("\nfirst come first serve algorithm\n");
  16. printf("\nprocess Id\t waiting time\t turnaround time\n");
  17. printf("1\t\t0\t\t%d\n",t[0]);
  18. sum=0;
  19. twt=0;
  20. ttat=t[0];
  21.  
  22. for(i=1;i<n;i++){
  23. sum=sum+t[i];
  24. wt=sum;
  25.  
  26. tat=sum+t[i];
  27. twt=twt+wt;
  28. ttat=ttat+tat;
  29. printf("%d\t\t%d\t\t%d\n",i+1,wt,tat);
  30. printf("\n\n");
  31.  
  32. }
  33. awt=(float)twt/n;
  34. atat=(float)ttat/n;
  35. printf("average waiting time %4.2f",awt);
  36. printf("average turn arounf time %4.2f",atat);
  37. }
Success #stdin #stdout 0.01s 5280KB
stdin
5
10
20
30
40
stdout
entr no of processors:enter the burst time of process no 1:enter the burst time of process no 2:enter the burst time of process no 3:enter the burst time of process no 4:enter the burst time of process no 5:
first come first serve algorithm

process Id	 waiting time	 turnaround time
1		0		10
2		20		40


3		50		80


4		90		130


5		91		92


average waiting time 50.20average turn arounf time 70.40