fork(1) download
  1. #include <stdio.h>
  2.  
  3. void bubble_sort(int list[], int n){
  4. int t,temp;
  5. for(t=0;t<n-1;t++){
  6. for(int j=0;j<n-t-1;j++){
  7. if(list[j]>list[j+1]){
  8. temp=list[j];
  9. list[j]=list[j+1];
  10. list[j+1]=temp;
  11. }
  12. }
  13. }
  14. }
  15.  
  16. int main(void) {
  17. int n;
  18. scanf("%d",&n);
  19. int num[n];
  20. for(int i=0;i<n;i++){
  21. int input;
  22. scanf("%d",&input);
  23. num[i]=input;
  24. }
  25. bubble_sort(num,n);
  26. for(int i=0;i<n;i++){
  27. printf("%d\n",num[i]);
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5256KB
stdin
5
5
2
3
4
1
stdout
1
2
3
4
5