Open In App

asin() and atan() functions in C/C++ with Example

Last Updated : 31 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In C++, asin() and atan() is a predefined function used for mathematical calculations. math.h is the header file required for various mathematical functions. All the functions available in this library take double as an argument and return double as the result.

asin() Method 

asin() function is used to find the arc sine of a number means give a sin value to this function it will return the angle in radian corresponding to that value. In trigonometric, arc sine is the inverse operation of sine. 

Note: The argument passed to this function must be in the range of [-1, 1] and asin() function returns the values in the range of [-?/2, ?/2].

Syntax:  

double asin(double k)
Parameters:
k is the value whose corresponding angle we have to find. 

Example: 

CPP




// CPP code to illustrate
// the use of asin function
#include <bits/stdc++.h>
using namespace std;
 
#define PI 3.14159265
 
int main()
{
    double k, ret, val;
 
    // Take any value between [-1, 1]
    k = 0.5;
    // asin() returns value in the range of [-?/2,?/2]
    ret = asin(k);
    val = (ret * 180) / PI;
    cout << "The arcsine of " << k << " is " << ret
         << " radians or " << val << " degrees";
 
    return 0;
}


Output: 

The arcsine of 0.5 is 0.523599 radians or 30 degrees 

Time Complexity: O(1)

Auxiliary Space: O(1)

atan() Method 

atan() function is used to find the arc tangent of a number means gives a tangent value to this function it will return the angle in radians corresponding to that value. arc tangent is the inverse operation of a tangent. This function accepts all the real numbers and atan() function returns the values in the range of [-?/2, ?/2].

Syntax:  

double atan(double k)
Parameters:
k is the value whose corresponding angle we have to find.

Example

CPP




// CPP code to illustrate
// the use of atan function
#include <bits/stdc++.h>
using namespace std;
 
#define PI 3.14159265
 
int main()
{
    double k, ret, val;
 
    // Take any value
    k = 1.0;
    ret = atan(k);
    val = (ret * 180) / PI;
    cout << "The arctangent of " << k << " is " << ret
         << " radians or " << val << " degrees";
 
    return 0;
}


Output: 

The arctangent of 1 is 0.785398 radians or 45 degrees 

Time Complexity: O(1)

Auxiliary Space: O(1)

Let us see the differences in a tabular form as shown below as follow:

asin() atan()
It is used to return the principal value of the arc sine of x. It is used to return the principal value of the arc tangent of x
It takes one parameter that is the value whose arc sine is computed It takes one parameter that is the value whose arc tangent is computed.
Its return type is integer. Its return type is integer.
It is defined in math.h header file. It is defined in math.h header file.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads