What is the cosh() function in C++?

Overview

The cosh() function in C++ is used to return the hyperbolic cosine of an angle given in radians.

Mathematically:

Cosh(x) = (ex)+(1/ex)2\frac{(e^x) + (1/e^x)}{2}

Syntax

double cosh(double x);
float cosh(float x);
long double cosh(long double x);

Parameter value

The cosh() function takes a single argument x, which represents the hyperbolic angle in radians.

Return value

The cosh() function returns the hyperbolic cosine of the argument passed to it.

Example

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// creating a variable
double x = 5.25, result;
// applying the cosh() function
result = cosh(x);
// printing our output
cout << "cosh(x) = " << result << endl;
return 0;
}

Explanation

  • In line 6, we declare a variable x.
  • In line 10, we call the cosh() function for the variable x and assign the output to a new variable result.
  • In line 13, we print the variable result.

Free Resources