📅  最后修改于: 2023-12-03 14:39:49.340000             🧑  作者: Mango
The acos()
function in C++ is used to calculate the arc cosine value of the given argument. The function returns the principal value of the arc cosine of the given argument, in the range from 0 to π, expressed in radians.
The syntax of the acos()
function is as follows:
#include <cmath>
double acos(double x);
Here, x
is the argument whose arc cosine value is to be calculated. The function returns the arc cosine value of x
.
The acos()
function returns the arc cosine value of the given argument, in the range from 0 to π, expressed in radians.
Here are few examples to demonstrate the usage of acos()
function in C++.
#include <iostream>
#include <cmath>
int main() {
double x = 0.5;
double result = acos(x);
std::cout << "The arc cosine value of " << x << " is: " << result << std::endl;
x = -0.5;
result = acos(x);
std::cout << "The arc cosine value of " << x << " is: " << result << std::endl;
return 0;
}
Output:
The arc cosine value of 0.5 is: 1.0472
The arc cosine value of -0.5 is: 2.0944
x
is outside the range [-1, 1], the acos()
function returns a NaN (not-a-number) value.acos()
function returns values in radians. To convert the radians to degrees, multiply with the conversion factor (180/π).