Home > Backend Development > C++ > C++ program to find arcsine with given value

C++ program to find arcsine with given value

WBOY
Release: 2023-09-08 09:33:02
forward
925 people have browsed it

C++ program to find arcsine with given value

In trigonometry, we most commonly use several ratios: sine, cosine, tangent, and a few others. From a given perspective, these ratios can be calculated. However, if we have ratio values, we can also calculate the angle using inverse trigonometric functions.

In this article, we will discuss how to get angles in radians from sine values ​​using the arcsine (arcsine) method in C.

asin() function

asin() method is used to calculate angles using the inverse trigonometric sine function. This function exists in the C standard library. We need to import the cmath library to use this method. This function returns the angle in radians by taking a sine value as input. The following uses simple syntax -

grammar

#include < cmath >
asin( <sine value> )
Copy after login

The sine value must be in the range [-1 to 1] (inclusive). Otherwise, a domain error is raised and Not-A-Number (nan) is returned. The range of return values ​​is $\mathrm{[-\:\frac{\pi}{2},\frac{\pi}{2}]}$ (both inclusive)

algorithm

  • Take sine value x as input
  • Use asin(x) to calculate sin−1(x)
  • Return results.

Example

#include <iostream>
#include <cmath>
using namespace std;

float solve( float x ) {
   float answer;
   answer = asin( x );
   return answer;
}

int main()
{
   float angle, ang_deg;
   angle = solve( 0.7071067 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given sine value 0.7071067 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 0.866025 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given sine value 0.866025 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 1 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given sine value 1 is: " <<; angle << " = " << ang_deg << " (in degrees)" << endl;

   angle = solve( 0.5 );
   ang_deg = angle * 180 / 3.14159;

   cout << "The angle (in radian) for given sine value 0.5 is: " << angle << " = " << ang_deg << " (in degrees)" << endl;
}
Copy after login

Output

The angle (in radian) for given sine value 0.7071067 is: 0.785398 = 45 (in degrees)
The angle (in radian) for given sine value 0.866025 is: 1.0472 = 60 (in degrees)The angle (in radian) for given sine value 1 is: 1.5708 = 90.0001 (in degrees)
The angle (in radian) for given sine value 0.5 is: 0.523599 = 30 (in degrees)
Copy after login

Here the asin() function takes a sine value and returns the angle in radian format. Here we use the following formula to convert the output from radians to degrees

$$\mathrm{\theta_{deg}\:=\:\theta_{rad}\:\times\:\frac{180}{\pi}}$$

in conclusion

To perform inverse trigonometric operations based on sine values, we use the asin() function from the cmath library. This function takes a sine value as input and returns the given angle in radians. In older versions of C/C, the return type was double, but later C versions used additional overloads of float and long-double. When an integer value is passed as a parameter, it converts the input parameter to double and calls the asin() method corresponding to the double type parameter.

The above is the detailed content of C++ program to find arcsine with given value. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template