📜  用于说明三角函数的C++程序

📅  最后修改于: 2021-05-05 00:40:49             🧑  作者: Mango

math.h标头包含用于执行基本数字运算的方法,例如基本指数,对数,平方根和三角函数。为了使用这些功能,您需要包括头文件math.h。
注意:所有功能均以弧度而非度为单位输入

下面是可从math.h标头中使用的各种三角函数:

  1. sin :该函数将angle(以弧度单位)作为参数,并返回其正弦值,可以使用正弦曲线进行验证。

    例子:

    // 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
    
  2. 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
    
  3. tan :此函数将angle(以弧度单位)作为参数并返回其切线值。这也可以使用三角函数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
    
  4. 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
    
  5. 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
    
  6. 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
    
  7. 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
    
  8. 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
    
  9. 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
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”