w3resource

C tanh() function

C tanh() function - Calculate hyperbolic tangent

Syntax:

double tanh(double x)

The tanh() function is calculate the hyperbolic tangent of x.

Parameters:

Name Description Required /Optional
x This is the floating point value. Required

Return value from tanh()

  • Returns the value of the hyperbolic tangent of x.

Example: tanh() function

The following example shows the usage of tanh() function.

#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double pi, x, y; 
   pi = 3.1415926535;
   x = pi/2;
   y = tanh(x); 
   printf("tanh( %lf ) = %lf\n", x, y);
} 

Output:

tanh( 1.570796 ) = 0.917152

C Programming Code Editor:

Previous C Programming: C sinh()
Next C Programming: C exp()



Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
{
    ptr = 0;// oops, I meant *ptr = 0
}

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q