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.

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

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.

Sharpen Your Fundamentals with Free Learning

Return Values for tanh() Function in C

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

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.