# Library Function acos in Math Class

## Library Function acos of math.h Header File in C

On this page we will discuss about library function acos in math class which is used in C. The C header file math.h contains the standard math library functions that can be used for performing various mathematical operations. The acos function returns the arc cosine of x in radians.

## Library Function acos of math.h Header File

In C programming language the acos function is included in math.h header file. The acos function takes input argument in the range of $(-1 \leq x \leq 1)$ and returns the inverse cosine of parameter x in radians.

### Declaration of acos function

 double acos(double x)
We can find the inverse cosine of different data types like int, float or long double by using the cast operator which explicitly converts the data type to double as given below:
int x = 0;double result; result = acos(double(x));

### Parameters of acos function

The value of cosine lies in the range of -1 to 1, hence the acos function accepts input argument or values in the range of [-1,+1].

ParameterDescription
double valueThis value of double function is in between – 1 and +1 inclusive.

### Return value of acos function

The acos function returns the principal value of inverse cosine of  parameter x in the range of [0,$\Pi$ ] in radians. The function returns NaN if the parameter passed to acos function is greater than 1 or less than -1.

ParameterReturn Value
x = [-1, +1][0,$\Pi$ ] in radians
x>1 or x<-1NaN (not a number)

### Implementation of Library Function math.h acos

The following code shows the use of acos function with different parameters passed to the function.

Run
#include <stdio.h>
#include <math.h>
int main ()
{
// constant PI is defined
const double PI = 3.1415926;
double y, inverse_of_function;

y = -0.8;
inverse_of_function = acos (y);
printf ("The inverse of cos(%.2f) function = %.2lf in radians\n", y,inverse_of_function);

inverse_of_function = acos (y) * 180 / PI;
printf ("The inverse of cos(%.2f) function = %.2lf in degrees\n", y,inverse_of_function);

// parameter not in range
y = 1.5;
inverse_of_function = acos (y);
printf ("The inverse of cos(%.2f) function= %.2lf", y,inverse_of_function);

return 0;
}


### Output:

The inverse of cos(-0.80) function = 2.50 in radians
The inverse of cos(-0.80) function = 143.13 in degrees
The inverse of cos(1.50) function= nan


### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others