C++ acos()

C++ acos() returns inverse cosine of a number in radians.

Syntax

The syntax of C++ acos() is

acos(x)

where

ParameterDescription
xA double, float, or long double.

Returns

The return value depends on the type of value passed for parameter x. The return value of acos(x) is

  • double if x is double.
  • float if x is float.
  • long double if x is long double.

The synopsis of acos() function is

double acos(double x);
float acos(float x);
long double acos(long double x);
double acos(T x); // for integral type argument values

acos() is a function of cmath library. Include cmath library in the program, if using acos().

Example

In this example, we read x value from the user and find the inverse cosine of this value using acos() function.

C++ Program

#include <iostream>
#include<cmath>
using namespace std;

int main() {
    double x;
    cout << "Enter a value : ";
    cin >> x;
    
    double result = acos(x);
    cout << "acos(" << x << ") : " << result << " radians" << endl;
}

Output

Enter a value : 0.5
acos(0.5) : 1.0472 radians
Program ended with exit code: 0
Enter a value : 0
acos(0) : 1.5708 radians
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned the syntax of C++ acos(), and how to use this function to find the inverse consine of a number, with the help of examples.