#include <iostream>

using namespace std;

// function to sort array x with n elements
void sort(float* x, int n)
{
  
  // variable to count number of swapped elements in one pass
  int nswap;

  do {
    
    // reset counter
    nswap = 0;

    for (int i=0; i<n-1; i++) {

      // check if elements are in correct order
      if ( x[i+1] < x[i] ) {

        // if not - swap elements 
        float tmp = x[i+1];
        x[i+1]    = x[i];
        x[i]      = tmp;
        
        // increment counter
        nswap++;
      }
    }

    // stop when no swaps were necessary -> array is sorted
  } while (nswap > 0);
}


int main()
{

  // allocate array
  float x[10] = { 1.63, 2.83, 9.47, 2.32, 4.85, 
                  9.57, 7.44, 5.4, 7.4, 7.6 };

  // sort array
  sort (x,10);

  // print array
  for (int i=0; i<10; i++) {
    cout << "x[" << i << "]: " << x[i] << endl;
  }
  
  return 0;
}