我要用c++编一个程序计算数值P,公式如图,a、b是变量,我要输入a、b的不同值来计算P,对于会c++的同学应该不难,可惜我是个编程小白,数据又特别多,能否把完整的程序给我,谢谢了,如果好用我再追加!
第1个回答 2017-07-08
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a, b, P;
cout << "输入a b的值:";
cin >> a >> b;
P = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306 * pow(a, 1.5) * pow(b, 1.5);
cout << "P = " << P << endl;
return true;
}
#include <math.h>
using namespace std;
int main()
{
double a, b, P;
cout << "输入a b的值(输入任意非数字退出):";
while (cin >> a >> b)
{
P = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306 * pow(a, 1.5) * pow(b, 1.5);
cout << "P = " << P << endl << endl;
cout << "输入a b的值(输入任意非数字退出):";
}
return true;
}
#include <math.h>
using namespace std;
int main()
{
double a, b, P;
cout << "输入a b的值:";
cin >> a >> b;
P = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306 * pow(a, 1.5) * pow(b, 1.5);
cout << "P = " << P << endl;
return true;
}
这个运算一次就退出,如果你要一直循环输入数据的话用这个
#include <iostream>#include <math.h>
using namespace std;
int main()
{
double a, b, P;
cout << "输入a b的值(输入任意非数字退出):";
while (cin >> a >> b)
{
P = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306 * pow(a, 1.5) * pow(b, 1.5);
cout << "P = " << P << endl << endl;
cout << "输入a b的值(输入任意非数字退出):";
}
return true;
}
如果你要从文件读入大量数据请追问
第2个回答 推荐于2017-08-24
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
float a, b;
while (cin >> a >> b)
{
float p = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306*pow(a, 15)*pow(b, 15);
cout << p << endl;
}
system("pause");
return 0;
}本回答被网友采纳
#include<cmath>
using namespace std;
int main()
{
float a, b;
while (cin >> a >> b)
{
float p = 0.0204*a*pow(b, 1.775) + 0.0000548*a*a*b*b + 0.0000306*pow(a, 15)*pow(b, 15);
cout << p << endl;
}
system("pause");
return 0;
}本回答被网友采纳
第3个回答 推荐于2017-08-26
double p,a,b;
a=1.0;//自定义
b=1.0;//自定义
p=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0.0000306*pow(a,15)*pow(b,15);本回答被网友采纳
a=1.0;//自定义
b=1.0;//自定义
p=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0.0000306*pow(a,15)*pow(b,15);本回答被网友采纳
第4个回答 2012-12-21
#include <stdio.h>
#include <math.h>
main()
{
float a,b,P;
printf("请输入a的值:");
scanf("%f",&a);
printf("请输入b的值:");
scanf("%f",&b);
P=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0,0000306*pow(a,15)*pow(b,15);
printf("%f\n",P);
return 0;
}
如果你a、b的值存在一个文件中,那么把下面这四句:
printf("请输入a的值:");
scanf("%f",&a);
printf("请输入b的值:");
scanf("%f",&b);
改成文件读入,把printf("%f\n",P);这句改成文件写入,把p结果写到一个文本中,这样就可以一次计算很多数据了。本回答被网友采纳
#include <math.h>
main()
{
float a,b,P;
printf("请输入a的值:");
scanf("%f",&a);
printf("请输入b的值:");
scanf("%f",&b);
P=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0,0000306*pow(a,15)*pow(b,15);
printf("%f\n",P);
return 0;
}
如果你a、b的值存在一个文件中,那么把下面这四句:
printf("请输入a的值:");
scanf("%f",&a);
printf("请输入b的值:");
scanf("%f",&b);
改成文件读入,把printf("%f\n",P);这句改成文件写入,把p结果写到一个文本中,这样就可以一次计算很多数据了。本回答被网友采纳
第5个回答 推荐于2017-08-16
#include <math.h>
#include <iostream>
using namespace std;
int main() {
int a=0;int b=0;double p=0.0;
cin>>a>>b;
p=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0.0000306*pow(a,15)*pow(b,15)
cout<<p;
return 0;
}本回答被网友采纳
#include <iostream>
using namespace std;
int main() {
int a=0;int b=0;double p=0.0;
cin>>a>>b;
p=0.0204*a*pow(b,1.775)+0.0000548*pow(a,2)*pow(b,2)+0.0000306*pow(a,15)*pow(b,15)
cout<<p;
return 0;
}本回答被网友采纳