Type float stored in array, sorted by sort() - C++ STL Algorithm

C++ examples for STL Algorithm:sort

Description

Type float stored in array, sorted by sort()

Demo Code

#include <iostream>
#include <algorithm>
using namespace std;
int main()/*w  w w . ja  v  a 2s  .c  o  m*/
{
   int j=0, k;
   char ch;
   float fpn, farr[100];
   do {
      cout << "Enter a floating point number: ";
      cin >> fpn;
      farr[j++] = fpn;
      cout << "Enter another ('y' or 'n'): ";
      cin >> ch;
   } while(ch == 'y');
   sort(farr, farr+j);
   for(k=0; k<j; k++)
      cout << farr[k] << ", ";
   cout << endl;
   return  0;
}

Result


Related Tutorials