📜  带有示例的C / C++中的asin()和atan()函数

📅  最后修改于: 2021-05-30 15:25:43             🧑  作者: Mango

在C++中,asin()和atan()是用于数学计算的预定义函数。 math.h是各种数学功能所需的头文件。该库中所有可用的函数都将double作为参数,并返回double作为结果。

asin()

asin()函数用于查找数字的反正弦值,为该函数提供正弦值,它将以弧度返回对应于该值的角度。在三角学中,反正弦是正弦的逆运算。
注意:传递给此函数的参数必须在[-1,1]范围内,而asin()函数将返回在[-?/ 2,?/ 2]范围内的值
句法:

double asin(double k)

Parameters:
k is the value whose corresponding angle we have to find. 
CPP
// CPP code to illustrate
// the use of asin function
#include 
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;
}


CPP
// CPP code to illustrate
// the use of atan function
#include 
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;
}


输出:

The arcsine of 0.5 is 0.523599 radians or 30 degrees 

晒黑()

atan()函数用于查找数字的反正切值,表示对该函数给出正切值,它将返回与该值对应的以弧度为单位的角度。反正切是切线的逆运算。该函数接受所有实数,并且atan()函数返回[-?/ 2,?/ 2]范围内的值
句法:

double atan(double k)

Parameters:
k is the value whose corresponding angle we have to find.

CPP

// CPP code to illustrate
// the use of atan function
#include 
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;
}

输出:

The arctangent of 1 is 0.785398 radians or 45 degrees 
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”