acos() Math Function In C++ is a mathematical function that helps to find out the inverse cosine of a number.
The inverse cosine of a number in radian is computed with this function.
acos(x) = cos -1x
Syntax:
Let’s say the number is x. The syntax would be as follows:
float acos(float x);
double acos(double x);
long double acos(long double x);
double acos(integral x);
Parameter:
x: The value for which the arc cosine must be computed. It should fall between [-1,1].
Return value:
Parameter | Return value |
---|---|
-1≤x≤1 | (0,∏) |
x<-1 or x>1 | Not a number |
Example-1:
Let’s look at a basic case where x is higher than 1.
#include <iostream> #include<math.h> using namespace std; int main() { float degree=90; float x=degree*3.14/180; std::cout << "Value of cosine is :" <<cos(x)<< std::endl; cout<<"Inverse of cosine is :"<<acos(x); return 0; }
Output:
Value of cosine is :0.000796274
Inverse of cosine is :nan
In this case, the acos() function computes the inverse cosine of an integer when x is larger than 1.
Join Our Community
Join our WhatsApp Group To know more About Programming Language tips, tricks and knowledge about programming and how to start learning any programming language.
Example-2:
Let’s look at a basic case where x is equal to zero.
#include <iostream> #include<math.h> using namespace std; int main() { float degree=0; float x=degree*3.14/180; std::cout << "Value of cosine is :" <<cos(x)<< std::endl; cout<<"Inverse of cosine is :"<<acos(x); return 0; }
Output:
Value of cosine is :1
Inverse of cosine is :1.5708
When the value of x is equal to zero, the acos() function computes the inverse cosine of a number.
Example-3
Let’s have a look at a basic case where x is smaller than -1.
#include <iostream> #include<math.h> using namespace std; int main() { float degree= -60; float x=degree*3.14/180; std::cout << "Value of cosine is :" <<cos(x)<< std::endl; cout<<"Inverse of cosine is :"<<acos(x); return 0; }
Output:
Value of cosine is :0.50046
Inverse of cosine is :nan
In this case, the acos() function computes the inverse cosine of an integer when x is less than -1.