Syntax
#include <math.h> double acos(double x);Description
acos calculates the arccosine of x, expressed in radians, in the range 0 to the value of pi.
acos returns the arccosine of x. The value of x must be between -1 and 1 inclusive. If x is less than -1 or greater than 1, acos sets errno to EDOM and returns 0.
This example prompts for a value for x. It prints an error message if x is greater than 1 or less than -1; otherwise, it assigns the arccosine of x to y.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define  MAX           1.0
#define  MIN          -1.0
int main(void)
{
   double x,y;
   printf("Enter x\n");
   scanf("%lf", &x);
   /* Output error if not in range */
   if (x > MAX)
      printf("Error: %lf too large for acos\n", x);
   else
      if (x < MIN)
         printf("Error: %lf too small for acos\n", x);
      else {
         y = acos(x);
         printf("acos( %lf ) = %lf\n", x, y);
      }
   return 0;
   /****************************************************************************
      For the following input: 0.4
      The output should be:
      Enter x
      acos( 0.400000 ) = 1.159279
   ****************************************************************************/
}
Related Information