如何将此等式转换为C ++

时间:2019-01-26 15:42:41

标签: c++

我正在尝试将此等式转换为c++代码:

x = (10π)/(a+b)*sinC^3+3(ln a)(tan C)

这是我的尝试:

#include <iostream>
#include <iomanip>
#include <math.h> using namespace std;
int main()
{
    float x, y, z, a, b, C, PI;
    cout << endl << "Enter value a=";
    cin >> a;
    cout << "Enter value b=";
    cin >> b;
    cout << "Enter angle C in degrees=";
    cin >> C;
    PI = 3.1416;
    C = C * PI / 180;
    x = ((10 * PI) / (a + b)) * pow(sin(C), 3);
    +3 * (log(a)) * (tan(C));
    y = 0;
    z = 0;
    cout << fixed << setprecision(4);
    cout << endl << "x = " << x;
    cout << endl << "y = " << y;
    cout << endl << "z = " << z;
}

1 个答案:

答案 0 :(得分:3)

Pi 在math.h中定义为M_PI

正弦波在math.h中定义为double sin(double)

切线在math.h中定义为double tan(double)

自然对数在math.h中定义为double ln(double)

功率在math.h中定义为double pow(double,double)


您写道:

x = ((10 * PI) / (a + b)) * pow(sin(C), 3);
    +3 * (log(a)) * (tan(C));

第二个1/2(从+3开始)不是原始表达式的一部分,原始表达式以分号结尾。

尝试:

x = ((10 * PI) / (a + b)) * pow(sin(C), 3) + 3 * (log(a)) * (tan(C));

此外,请确保您了解log (base10)ln (自然对数)之间的区别。