C library - asin() function



The C math library asin() function is used to returns the arcsine (inverse sine) of passed 'arg' in radians in the range [π/2, π/2].

The inverse sine, also known as the arcsine. It is the inverse of the sine function, which reverses the sine function's effect. It is denoted as sin1(x) or asin(x).

For a given value 'arg' in the range [1, 1], the inverse sine function sin1(arg) returns the angle θ in the range [π/2, π/2].

Syntax

Following is the syntax of the C asin() function −

 double asin( double arg ); 

Parameters

This function accepts a single parameter −

  • arg − It is the argument for which arcsine is to be calculated. It will be type double and should be within the range [-1, 1].

Return Value

If no errors occur, the arc sine of the argument (arg) is returned in the range [-π/2, +π/2] in radians.

Example 1

Following is the basic c program to demonstrate the use of asin() to obtain an angle in radians.

 #include <stdio.h> #include <math.h> int main() { double arg = 1.0; double res = asin(arg); printf("The arc sine of %f is %f radians.\n", arg, res); return 0; } 

Output

Following is the output −

 The arc sine of 1.000000 is 1.570796 radians. 

Example 2

Let's create another example, we use the asin() function to obtain the inverse sine value in radian, then after in degree.

 #include <stdlib.h> #include <stdio.h> #include <math.h> #define PI 3.14159265 int main() { double k = 0.5; double res = asin(k); // Convert radians to degrees double val = (res * 180) / PI; printf("The arcsine of %f is %f radians or degree %f degree. \n", k, res, val); return 0; } 

Output

Following is the output −

 The arcsine of 0.500000 is 0.523599 radians or degree 30.000000 degree. 

Example 3

Now, Create another c program to display the value of the arcsine. If the 'k' lies between -1 to 1 then display the arcsine value, otherwise Invalid input!

 #include <stdio.h> #include <math.h> #define PI 3.14159265 int main() { double k = -5.0; if (k >= -1.0 && k <= 1.0) { double res = asin(k); double val_degrees = (res * 180.0) / PI; printf("The arcsine of %.2f is %.6f radians or %.6f degrees\n", k, res, val_degrees); } else { printf("Invalid input! The value must be between -1 and 1.\n"); } return 0; } 

Output

Following is the output −

 Invalid input! The value must be between -1 and 1. 
Advertisements