math.h 头文件包含执行基本数值运算的方法,例如基本指数、对数、平方根和三角函数。为了使用这些函数,您需要包含头文件math.h 。
注意:所有函数都以弧度而不是度数作为输入
下面是可以从 math.h 头文件中使用的各种三角函数:
- sin :此函数以角度(以弧度为单位)作为参数并返回其正弦值,该值可以使用正弦曲线进行验证。
例子:
// C++ program to illustrate // sin trigonometric function #include
#include using namespace std; int main() { double x = 2.3; cout << "Sine value of x = 2.3: " << sin(x) << endl; return 0; } 输出:Sine value of x = 2.3: 0.745705
- cos :此函数以角度(以弧度为单位)作为参数并返回其余弦值,该余弦值可以使用余弦曲线进行验证。
例子:
// C++ program to illustrate // cos trigonometric function #include
#include using namespace std; int main() { double x = 2.3; cout << "Cosine value of x = 2.3: " << cos(x) << endl; return 0; } 输出:Cosine value of x = 2.3: -0.666276
- tan :此函数以角度(以弧度为单位)作为参数并返回其切线值。这也可以使用三角函数来验证,因为 Tan(x) = Sin(x)/Cos(x)。
例子:
// C++ program to illustrate // tan trigonometric function #include
#include using namespace std; int main() { double x = 2.3; cout << "Tangent value of x = 2.3: " << tan(x) << endl; return 0; } 输出:Tangent value of x = 2.3: -1.11921
- acos :此函数返回参数的反余弦值。 acos 的参数必须在 -1 到 1 的范围内;否则,会发生域错误。
例子:
// C++ program to illustrate // acos trigonometric function #include
#include using namespace std; int main() { double x = 1.0; cout << "Arc Cosine value of x = 1.0: " << acos(x) << endl; return 0; } 输出:Arc Cosine value of x = 1.0: 0
- asin :此函数返回参数的反正弦。 asin 的参数必须在 -1 到 1 的范围内;否则,会发生域错误。
例子:
// C++ program to illustrate // asin trigonometric function #include
#include using namespace std; int main() { double x = 1.0; cout << "Arc Sine value of x = 1.0: " << asin(x) << endl; return 0; } 输出:Arc Sine value of x = 1.0: 1.5708
- atan :此函数返回 arg 的反正切。
例子:
// C++ program to illustrate // atan trigonometric function #include
#include using namespace std; int main() { double x = 1.0; cout << "Arc Tangent value of x = 1.0: " << atan(x) << endl; return 0; } 输出:Arc Tangent value of x = 1.0: 0.785398
- atan2 :此函数返回 (a)/(b) 的反正切。
例子:
// C++ program to illustrate // atan2 trigonometric function #include
#include using namespace std; int main() { double x = 2.3, y = 1.0; cout << "Arc Tangent 2 value of x = 2.3 and y = 1.0: " << atan2(x, y) << endl; return 0; } 输出:Arc Tangent 2 value of x = 2.3 and y = 1.0: 1.16067
- cosh :此函数返回所提供参数的双曲余弦值。提供的参数值必须以弧度为单位。
例子:
// C++ program to illustrate // cosh trigonometric function #include
#include using namespace std; int main() { double x = 57.3; // in degrees cout << "Hyperbolic Cosine of x=57.3: " << cosh(x) << endl; return 0; } 输出:Hyperbolic Cosine of x=57.3: 3.83746e+24
- tanh :此函数返回所提供参数的双曲正切值。提供的参数值必须以弧度为单位。
例子:
// C++ program to illustrate // tanh trigonometric function #include
#include using namespace std; int main() { double x = 57.3; // in degrees cout << "Hyperbolic Tangent of x=57.3: " << tanh(x) << endl; return 0; } 输出:Hyperbolic Tangent of x=57.3: 1
以下是三角函数:
// C++ program to illustrate some of the
// above mentioned trigonometric functions
#include
#include
using namespace std;
int main()
{
double x = 2.3;
cout << "Sine value of x = 2.3: "
<< sin(x) << endl;
cout << "Cosine value of x = 2.3: "
<< cos(x) << endl;
cout << "Tangent value of x = 2.3: "
<< tan(x) << endl;
x = 1.0;
cout << "Arc Cosine value of x = 1.0: "
<< acos(x) << endl;
cout << "Arc Sine value of x = 1.0: "
<< asin(x) << endl;
cout << "Arc Tangent value of x = 1.0: "
<< atan(x) << endl;
x = 57.3; // in degrees
cout << "Hyperbolic Cosine of x=57.3: "
<< cosh(x) << endl;
cout << "Hyperbolic tangent of x=57.3: "
<< tanh(x) << endl;
return 0;
}
输出:
Sine value of x = 2.3: 0.745705
Cosine value of x = 2.3: -0.666276
Tangent value of x = 2.3: -1.11921
Arc Cosine value of x = 1.0: 0
Arc Sine value of x = 1.0: 1.5708
Arc Tangent value of x = 1.0: 0.785398
Hyperbolic Cosine of x=57.3: 3.83746e+24
Hyperbolic tangent of x=57.3: 1
如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程和学生竞争性编程现场课程。