In this article, you will learn about C math library function acos() with explanation and example.

C math library function acos()

acos() is the standard C math library function that returns the arc cosine of the given argument in radian and is defined in math library math.h.

#include<math.h>

Function prototype of C math library function acos()

double acos( double n );

where,

n = floating point value between 1 and -1 (1 >= n >= -1).

This function returns the arc cosine of n in radians that range between 0 and pi [0, pi].

Note: acos( ) takes argument between 1 and -1 because the mathematical value of cosine is in the range of 1 and -1.

Example: C program to demonstrate the use of math library function acos()

/*Use of math library function acos*/

#include<stdio.h>
#include<math.h>
#define PI 3.1415926

int main()
{
   double x, y;

   x = 0.3;
   y = -0.3;

   //calculation arc cosine in radians
   printf("acos(%.2lf) = %.2lf (radians)\n\n", x, acos( x ));

   //calculation arc cosine in degrees
   printf("acos(%.2lf) = %.2lf (degree)\n\n", x, acos( x ) * 180 / PI );

   //calculation arc cosine in radians
   printf("acos(%.2lf) = %.2lf (radians)\n\n", y, acos( y ));

   //calculation arc cosine in degrees
   printf("acos(%.2lf) = %.2lf (degree)\n", y, acos( y ) * 180 / PI );

   return 0;
}

Output

c math function acos( )

Explanation

In the above program, we have calculated the arc cosine of x and y in radian and degree.

We have defined macro PI for representing the value of pi.