fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int sapxep (int *a[],int n)
  5. { int tam;
  6. for (int x=1;x<n;x++)
  7. {
  8. for (int y=x+1;y<=n;y++)
  9. {
  10. if ((*a)[x] > (*a)[y])
  11. {
  12. tam=(*a)[x];
  13. (*a)[x]=(*a)[y];
  14. (*a)[y]=tam;
  15. }
  16. }
  17. }
  18. }
  19. int main()
  20. {int n;
  21. cout << "nhap so phan tu cua mang " << endl;
  22. cin >> n;
  23. int *a= new int [n];
  24. for (int x=1;x<=n;x++)
  25. {
  26. cout << "nhap so thu "<<x<<endl;
  27. cin >> a[x];
  28. }
  29. sapxep(&a,n);
  30. for (int x=1;x<=n;x++)
  31. {
  32. cout << a[x]<< " "<<endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 3460KB
stdin
5
1 3 2 4 5
stdout
nhap so phan tu cua mang 
nhap so thu 1
nhap so thu 2
nhap so thu 3
nhap so thu 4
nhap so thu 5
1 
2 
3 
4 
5