I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the tan() function in the C++ programming as follows :
Code:
#include <valarray>
#include <iostream>
#include <iomanip>
int main( )
{
using namespace std;
double pi = 3.14159265359;
int j;
valarray<double> wa1 ( 9 );
for ( j = 0 ; j < 9 ; j++ )
wa1 [ j ] = ( pi/2 ) * ( 0.25 * j - 1 );
valarray<double> wa2 ( 9 );
cout << "The initial valarray is:\n";
for ( j = 0 ; j < 9 ; j++ )
cout << setw( 10 ) << wa1 [ j ]
<< " radians, which is "
<< setw( 5 ) << ( 180/pi ) * wa1 [ j ]
<< " degrees" << endl;
cout << endl;
wa2 = tan ( wa1 );
cout << "The tangent of the initial valarray is:\n ";
for ( j = 0 ; j < 9 ; j++ )
cout << wa2 [ j ] << endl;
}
Output
Code:
The initial valarray is:
-1.5708 radians, which is -90 degrees
-1.1781 radians, which is -67.5 degrees
-0.785398 radians, which is -45 degrees
-0.392699 radians, which is -22.5 degrees
0 radians, which is 0 degrees
0.392699 radians, which is 22.5 degrees
0.785398 radians, which is 45 degrees
1.1781 radians, which is 67.5 degrees
1.5708 radians, which is 90 degrees
The tangent of the initial valarray is:
9.6701e+012
-2.41421
-1
-0.414214
0
0.414214
1
2.41421
-9.6701e+012
Bookmarks