Home » C++ programming language

tanh() function with example in C++

C++ tanh() function: Here, we are going to learn about the tanh() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 28, 2019

C++ tanh() function

tanh() function is a library function of cmath header, it is used to find the hyperbolic tangent of the given value (hyperbolic angle), it accepts a number (x) and returns the hyperbolic tangent of x.

Syntax of tanh() function:

    tanh(x);

Parameter(s): x – is the number (hyperbolic angel) to be used to calculate the hyperbolic tangent.

Return value: double – it returns double type value that is the hyperbolic tangent of hyperbolic angle x.

Example:

    Input:
    float x = 2.45;
    
    Function call:
    tanh(x);    
    
    Output:
    0.985217

C++ code to demonstrate the example of tanh() function

// C++ code to demonstrate the example of 
// tanh() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    x = -10.23;
    cout<<"tanh("<<x<<"): "<<tanh(x)<<endl;

    x = 0;
    cout<<"tanh("<<x<<"): "<<tanh(x)<<endl;    

    x = 2.45;
    cout<<"tanh("<<x<<"): "<<tanh(x)<<endl;    
    
    return 0;
}

Output

tanh(-10.23): -1
tanh(0): 0
tanh(2.45): 0.985217

Reference: C++ tanh() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.