tanh() Function in C

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.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
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.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
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 .
Turn Learning into Career Growth
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.




