
我写的解一元二次方程程序当有虚根时解不出正确结果,是什么原因,怎么改?求教!
//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;
} 展开
//
#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;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询