C acos() function

C acos() function - Calculate arccosine

The acos() function is used to calculate the arccosine of a given number, expressed in radians, in the range 0 to pi.


double acos(double x)


Name Description Required /Optional
x Value whose arccosine is to be calculated. Required

Return value from acos()

  • Upon successful completion, the function return the arc cosine of x.
  • The value of x must be between -1 and 1 inclusive.

Example: acos() function

The following example shows the usage of acos() function.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX  1.0
#define MIN -1.0
int main(void)
  double x, y; 
  printf("Input the value of x: ");
  scanf( "%lf", &x );
  y = acos(x);
  if (x > MAX)
    printf( "Error: %lf not in the range!\n", x );
  else if (x < MIN)
    printf( "Error: %lf not in the range!\n", x );
    printf("acos(%lf) = %lf\n", x, y);


Input the value of x: 1
acos(1.000000) = 0.000000

Input the value of x: 1.5
Error: 1.500000 not in the range!

Input the value of x: -1.5
Error: -1.500000 not in the range!

C Programming Code Editor:

Previous C Programming: C math.h Home
Next C Programming: C asin()

Follow us on Facebook and Twitter for latest update.