
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
cosh() function in C++ STL
The cosh() function returns the hyperbolic cosine of an angle given in radians. It is an inbuilt function in C++ STL.
The syntax of the cosh() function is given as follows.
cosh(var)
As can be seen from the syntax, the function cosh() accepts a parameter var of data type float, double or long double. It returns the hyperbolic cosine of var.
A program that demonstrates cosh() in C++ is given as follows −
Example
#include <iostream> #include <cmath> using namespace std; int main() { double d = 5, ans; ans = cosh(d); cout << "cosh("<< d <<") = " << ans << endl; return 0; }
Output
cosh(5) = 74.2099
In the above program, first the variable d is initialized. Then hyperbolic cosine of d is found using cosh() and stored in ans. Finally the value of ans is displayed. This is demonstrated by the following code snippet.
double d = 5, ans; ans = cosh(d); cout << "cosh("<< d <<") = " << ans << endl;
If the value is provided in degrees, it is converted to radians before using cosh() function.as it returns the hyperbolic cosine of an angle given in radians A program to demonstrate this is as follows.
Example
#include <iostream> #include <cmath> using namespace std; int main() { double degree = 60, ans; degree = degree * 3.14159/180; ans = cosh(degree); cout << "cosh("<<degree<<") = " << ans << endl; return 0; }
Output
cosh(1.0472) = 1.60029
In the above program, the value is given in degree. So it is converted into radians and then the hyperbolic cosine is obtained using cosh(). Finally, the output is displayed. This is demonstrated by the following code snippet.
double degree = 60, ans; degree = degree * 3.14159/180; ans = cosh(degree); cout << "cosh("<<degree<<") = " << ans << endl;
- Related Articles
- cosh() function in PHP
- PHP cosh() Function
- cosh() function for complex number working with C++
- sinh() function in C++ STL
- atanh() function in C++ STL
- tanh() function in C++ STL
- acosh() function in C++ STL
- asinh() function in C++ STL
- acos() function in C++ STL
- atan2() function in C++ STL
- iswalnum() function in C++ STL
- iswalpha() function in C++ STL
- lldiv() function in C++ STL
- negate function in C++ STL
- iswpunct() function in C++ STL
