English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++acos() Function Usage and Example
This function returns the inverse cosine value of the number (parameter) in radians form in<cmath>Header file definition.
[Math] cos-1++]
double acos(double x); float acos(float x); long double acos(long double x); double acos(T x); //as an integer
the acos() function uses[-1,1]within the range of a single mandatory parameter. This is because the cosine value in1to-1of.
Assuming the parameter is in[-1,1]the range, then the acos() function returns a value within the range [0, π].
If the parameter is greater than1or less-1, then acos() returns NaN, which is not a number.
Parameter (x) | Return value |
---|---|
x = [-1,1] | [0, π] in radians |
-1> x or x> 1 | NaN (Not a Number) |
#include <iostream> #include <cmath> using namespace std; int main() { double x = 0.0, result; result = acos(x); cout << "acos(x) = " << result << " radians" << endl; cout << "acos(x) = " << result*180/3.1415 << "degrees" << endl; return 0; }
When the program is run, the output is:
acos(x) = 1.5708 radians acos(x) = 90.0027 degrees
#include <iostream> #include <cmath> using namespace std; int main() { int x = -1; double result; result = acos(x); cout << "acos(x) = " << result << " radians" << endl; // Convert the result to degrees cout << "acos(x) = " << result*180/3.1415 << " " degrees; return 0; }
When the program is run, the output is:
acos(x) = 3.14159 radians acos(x) = 180.005 degrees