acos Function in C

The acos function in C is a Math Library Function that calculates the trigonometric Arc Cosine value for the user-specified expression or value. The syntax of the acos is as shown below.

double acos(double number);

Parameter: The acos() function accepts a single parameter value, and its range is between -1 and +1. Remember, it only accepts a double date type, and for others, we must explicitly convert them to a double.

Return Value: The acos() function returns the arc cosine value for the given number, and it will be in the range of zero to π in radians.

C acos function Example

The acos Function in the math library helps you to find the trigonometry Arc Cosine for the specified values. This program asks the user to enter his/her own number, and then it will find the arc cosine of the user entered one.

TIP: Please refer to the math article in this Programming to calculate the COSINE value of a specified program expression.

#include <stdio.h>
#include <math.h>

int main()
{
  double acosValue, number;

  printf(" Please Enter the Floating Value between -1 to 1 :  ");
  scanf("%lf", &number);
  
  acosValue = acos(number);
  
  printf("\n The Arc Cosine value of %lf = %f ", number, acosValue);
  
  return 0;
}
acos function in C Example

Example 2: Here, we use the acos() function with a parameter value that is out of range (above 1 or below -1).

#include <stdio.h>
#include <math.h>

int main()
{
double a, b, c, d;
a = 2.5;
b = -3.5;
printf("%f\n", acos(a));
printf("%f", acos(b));
}
-nan(ind)
-nan(ind)

How to convert acos result to degrees in C?

By default, the math library acos function returns the arc cosine value in radians. To convert it to degrees, we must multiply the acos() result by 180/π.

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

int main()
{
double a, b, c;
a = 0.8;
b = acos(a);
c = acos(a) * 180.0 / PI;
printf("Radians = %f\n", b);
printf("Degrees = %.2f", c);
}
Radians = 0.643501
Degrees = 36.87

How to calculate PI using acos in C?

The arc cosine or acos(-1) returns the π value. Please refer to the asin() and atan() functions to find the arc sine and arctangent values.

#include <stdio.h>
#include <math.h>

int main(void)
{
double p = acos(-1.0);
printf("PI = %.15f\n", p);
return 0;
}
PI = 3.141592653589793

C acosf() and acosl() functions

There are explicit acosf() and acosl() functions to find the arc cosine value of the float and long double values. Instead of converting them to double, we can use the acosf() and acosl() methods.

#include <stdio.h>
#include <math.h>

int main()
{
float a, b;
long double x, y;

a = 0.8;
b = acosf(a);
printf("%f\n", b);

x = 0.5L;
y = acosl(x);
printf("%Lf", y);
}
0.643501
1.047198