The following program could states you that how you can use the sort() function in the C++ language programming while using the sort() function in the programming as shown below :
Code:
#include <valarray>
#include <iostream>
#include <cmath>
int main( )
{
using namespace std;
int g;
valarray<double> w1 ( 6 );
for ( g = 0 ; g < 5 ; g++ )
w1 [ g ] = g * g;
cout << "The initial valarray is: ( ";
for ( g = 0 ; g < 5 ; g++ )
cout << w1 [ g ] << " ";
cout << ")." << endl;
valarray<double> w2 = sqrt ( w1 );
cout << "The square root of the initial valarray is: ( ";
for ( g = 0 ; g < 5 ; g++ )
cout << w2 [ g ] << " ";
cout << ")." << endl;
}
Output
Code:
The initial valarray is: ( 0 1 4 9 16 ).
The square root of the initial valarray is: ( 0 1 2 3 4 ).
Bookmarks