fork download
  1. #include <iostream>
  2. using namespace std;
  3. void sort(float[], int);
  4.  
  5. int main()
  6. {
  7.  
  8. const int SIZE = 5;
  9. float a[SIZE];
  10.  
  11. std::cout << "Enter " << SIZE << "numbers:\n";
  12.  
  13. for(int i = 0; i<SIZE; i++)
  14. std::cin >> a[i];
  15. sort(a,5);
  16. std::cout << "In sorted order: ";
  17. for(int i = 0; i<SIZE; i++)
  18. std::cout << a[i] << " ";
  19. }
  20.  
  21. void sort (float a[], int n)
  22. {
  23. for (int i=1; i < n; i++)
  24. for (int j=0; j < n-i; j++)
  25. if (a[j] > a[j+1]) swap (a[j], a[j+1]);
  26. }
Success #stdin #stdout 0s 2988KB
stdin
3 4 5 6 1
stdout
Enter 5numbers:
In sorted order: 1 3 4 5 6