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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.