fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void mcout(int* l,int n)
  5. {
  6. for(int i=0;i<n;i++)
  7. {
  8. cout<<l[i]<<" ";
  9. }
  10. }
  11.  
  12. int main() {
  13. int n[100];
  14. int a,b,c;
  15. cin>>a;
  16. b=1;
  17. for(int i=0;i<a;i++)
  18. {
  19. cin>>n[i];
  20. }
  21. for(int i=0;i<a;i++)
  22. {
  23. for(int j=0;j<a-b;j++)
  24. {
  25. if(n[j]>n[j+1])
  26. {
  27. cout<<n[j]<<" "<<n[j+1]<<endl;
  28. c=n[j];
  29. n[j]=n[j+1];
  30. n[j+1]=n[j];
  31. }
  32. }
  33. b++;
  34. }
  35. mcout(n,a);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 4504KB
stdin
8 3 4 5 6 7 1 3 2
stdout
7 1
3 2
6 1
5 1
4 1
3 1
1 1 1 1 1 1 2 2