acosh() function in C++ STL

C++ProgrammingServer Side Programming

The acosh() function returns the arc hyperbolic cosine or the inverse hyperbolic cosine of an angle given in radians. It is an inbuilt function in C++ STL.

The syntax of the acosh() function is given as follows.

acosh(var)

As can be seen from the syntax, the function acosh() accepts a parameter var of data type float, double or long double. The value of this parameter should be greater than or equal to 1. It returns the arc hyperbolic cosine of var.

A program that demonstrates acosh() in C++ is given as follows.

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   double d = 12, ans;
   ans = acosh(d);
   cout << "acosh("<< d <<") = " << ans << endl;
   return 0;
}

Output

acosh(12) = 3.17631

In the above program, first the variable d is initialized. Then arc hyperbolic cosine of d is found using acosh() and stored in ans. Finally the value of ans is displayed. This is demonstrated by the following code snippet.

double d = 12, ans;
ans = acosh(d);
cout << "acosh("<< d <<") = " << ans << endl;

The result obtained by using the acosh() function can be converted into degrees and displayed. A program to demonstrate this is as follows.

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   double d = 12, ans;
   ans = acosh(d);
   ans = ans*180/3.14159;
   cout << "acosh("<<d <<") = " << ans << endl;
   return 0;
}

Output

acosh(12) = 181.989

In the above program, the arc hyperbolic cosine is obtained using acosh(). Then this value is converted into degrees. Finally, the output is displayed. This is demonstrated by the following code snippet.

double d = 12, ans;
ans = acosh(d);
ans = ans*180/3.14159;
cout << "acosh("<< d <<") = " << ans << endl;
raja
Published on 05-Oct-2018 14:07:36
Advertisements