acos() in c – acos C Library Function

acos() in c: The function double acos(double x); returns the arc cosine of x, expressed in radians. Arc cosine is the inverse operation of cosine, It is also known as cosine inverse.

Function prototype of acos

double acos(double x);

  • x : A floating point value whose arc cosine(inverse cosine) to be computed, in the interval [-1, 1] (including -1 and 1).

Return value of acos

Inverse cosine java: Function acos returns the principal arc cosine of x, in the interval [0, PI] radians.

C program using acos function

The following program shows the use of acos function to calculate inverse of cosine.

acos C Library Function

#include <stdio.h>
#include <math.h>
 
#define PI 3.14159
 
int main(){
    double input, radian, degree;
    /* Range of cosine function is from -1 to 1*/
    printf("Enter a floating number between -1 and 1\n");
    scanf("%lf", &input);
     
    radian = acos(input);
    /* 
     *  Radian to degree conversion
     *  One radian is equal to 180/PI degrees.
     */
    degree = radian * (180.0/PI);
     
    printf("The arc cosine of %0.4lf is %0.4lf in radian\n",
        input, radian);
    printf("The arc cosine of %0.4lf is %0.4lf in degree\n",
        input, degree);
         
    return 0;
}

Output

Enter a floating number between -1 and 1
0.5
The arc cosine of 0.5000 is 1.0472 in radian
The arc cosine of 0.5000 is 60.0001 in degree

Leave a Comment