题目
c++求二元一次方程的根
#include
#include
void main()
{
printf(" ★☆欢迎使用二元一次方程求根工具☆★\n\n\n");
float a,b,c,q,p,x1,x2;
printf(" ★请输入a,b,c的值★\n\n\n\n\n\n");
printf("a=");
scanf("%f",&a);
printf("b=");
scanf("%f",&b);
printf("c=");
scanf("%f",&c);
q=-b/2*a;p=sqrt(b*b-4*a*c);
x1=q-p;x2=q+p;
printf("x1=%f,x2=%f,&x1&x2\n");
}
系统给了一个warnings :warning C4244:'=' :conversion from 'double' to 'float',possible loss of data
而且我用这个运行后,计算结果,总是得x1=0.000000,x2=一个负的可大的数!
我的公式逻辑上有错误吗?还有,我想加一个判定条件
如果b^2-4ac
#include
#include
void main()
{
printf(" ★☆欢迎使用二元一次方程求根工具☆★\n\n\n");
float a,b,c,q,p,x1,x2;
printf(" ★请输入a,b,c的值★\n\n\n\n\n\n");
printf("a=");
scanf("%f",&a);
printf("b=");
scanf("%f",&b);
printf("c=");
scanf("%f",&c);
q=-b/2*a;p=sqrt(b*b-4*a*c);
x1=q-p;x2=q+p;
printf("x1=%f,x2=%f,&x1&x2\n");
}
系统给了一个warnings :warning C4244:'=' :conversion from 'double' to 'float',possible loss of data
而且我用这个运行后,计算结果,总是得x1=0.000000,x2=一个负的可大的数!
我的公式逻辑上有错误吗?还有,我想加一个判定条件
如果b^2-4ac
提问时间:2021-03-04
答案
警告很正常 输出有问题 改了 功能完善了#include #include #includevoid main() { printf(" ★☆欢迎使用二元一次方程求根工具☆★\n\n\n"); float a,b,c,x1,x2; while(1){printf(" ★请输入a,b,c的值★\n\n\n\n\n\n...
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
最新试题
热门考点
- 1设C为可逆矩阵,C^TAC=diag(d1,d2,…,dn),问:对角矩阵的对角元是否一定是A的特征值?
- 2五一劳动节做的事情 英语过去式 中英对译
- 3the teacher made sure i would always touch the botttom of the pool with my feet and that my head wae
- 4you must be prepared to change dictions.
- 5Can I get you anything while I’m up?
- 60到9的任意6位数的排列组合都是什么?能帮我排列出来吗?
- 760X-3600=40X+2400 怎么解?
- 8do have what you Tuesday on cllasses ?
- 9由于地球的自转,形成了什么?
- 10The poor boy had difficulty walking为什么前面用过去式后面的walk用现在进行时呢?