Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c++
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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;
}
Implementing the cosh() function

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.

RELATED TAGS

c++
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring