C++ 如何将此方程转换为C++;
我试图将这个等式转换为C++ 如何将此方程转换为C++;,c++,C++,我试图将这个等式转换为c++code: 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 va
c++
code:
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;
}
#包括
#包括
#包括使用名称空间标准;
int main()
{
浮点数x,y,z,a,b,C,PI;
库塔;
cout>b;
cout>C;
PI=3.1416;
C=C*PI/180;
x=((10*PI)/(a+b))*pow(sin(C),3);
+3*(对数(a))*(tan(C));
y=0;
z=0;
coutPi在math.h中定义为M_Pi
Sine在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
开始)不是原始表达式的一部分,该表达式以分号结尾
尝试:
另外,请确保您了解log
(base10)和ln
(自然日志)之间的区别。向代码显示您尝试了什么?#包含#包含#使用名称空间std;int main(){float x,y,z,a,b,C,PI;coutThanks for the code.我试图改进您的问题并格式化代码。您能解释一下这段代码的问题吗?它是否返回错误的值?我问的原因是这通常是一个好问题所必需的。
x = ((10 * PI) / (a + b)) * pow(sin(C), 3) + 3 * (log(a)) * (tan(C));