我写的解一元二次方程程序当有虚根时解不出正确结果,是什么原因,怎么改?求教!

//wl.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"st... // wl.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
int main(int argc, char* argv[])
{
float a,b,c,x1,x2,delt;
scanf("%f,%f,%f",&a,&b,&c);
delt=b*b-4*a*c;
if(delt>=0)
{
x1=(-b+sqrt(delt))/2/a;
x2=(-b-sqrt(delt))/2/a;
printf("x1=%f,x2=%f\n",x1,x2);
}
else
{
x1=-b/a/2;
x2=sqrt(-delt)/2/a;
printf("the complex number is %f+%fi,%f-%fi\n");
}
return 0;
}
展开
 我来答
百度网友fb116dc
2013-03-15 · TA获得超过688个赞
知道小有建树答主
回答量:439
采纳率:0%
帮助的人:500万
展开全部

printf("the complex number is %f+%fi,%f-%fi\n");修改为


printf("the complex number is %f+%fi,%f-%fi\n",x1,x2,x1,x2);


推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式