tanh() Function in C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Overview

The tanh() function in C is a function belonging to the math.h header that calculates and returns the hyperbolic tangent of an argument passed into it.

Syntax of tanh() Function in C

The return type of the hyperbolic tangent of x is double if we pass double value to it.

The return type of the hyperbolic tangent of x is long double if we pass long double value to it.

The return type of the hyperbolic tangent of x is float if we pass float value to it.

Parameters of tanh() Function in C

It takes only one argument, let's say x. Here x is a floating-point value that is expressed in radians.

Return Values for tanh() Function in C

It returns the hyperbolic tangent of the argument that is passed in radians.

Example of tanh() Function in C

Here is a program that shows the usage of the tanh() function to calculate the hyperbolic tangent of an angle in radians.

Output

What is tanh() Function in C?

The math.h library in C provides a function called tanh to compute and return the hyperbolic tangent of a value/argument. Here the value/arguments should be in radians. The return type of the hyperbolic tangent depends on the datatype of the tanh() function. In C, the return type of any function is the data type of the function that is defined.

Note:

  • Always remember to use the #include<math.h> statement while using the tanh function in C .

How to use the tanh() Function in C?

One can use the tanh() function in C by simply having the header file #include<math.h> at the beginning of their C code. All you have to do is call the function tanh() and include an argument in the function. Here the argument is basically a numeric value in radians. See the examples mentioned below to understand better.

Note:

  • tanh() only accepts one argument and it should be a floating point value.

More Examples

Example 1: Find the hyperbolic tangent for a given value.

Output

Explanation:

In the above example, we are trying to find the hyperbolic tangent for a given value and print it.

Example 2: Find the hyperbolic tangent of 'n' degrees

Output

Explanation:

In this example, we are trying to find the hyperbolic tangent for the given degrees. As we already know that the argument that goes into the tanh() function should be in radians. We first apply a formula to convert the given degrees into radians and then pass this as an argument into the tanh() function.

Example 3: Find the hyperbolic tangent of PI/3.

Output

Explanation:

In this example, we are trying to find the hyperbolic tangent of pi/3.

Conclusion

  • tanh() function calculates and returns the hyperbolic tangent of an argument passed into it.
  • tanh() function belongs to the math.h header in C.
  • tanh() takes only one argument that is a floating-point value expressed in radians.