#include<stdio.h>
#include<math.h>
#define EXP 0.00000001//定义一个很小的数
int main()
{
double a = 0.0;
double b = 0.0;
double c = 0.0;
scanf("%lf%lf%lf",&a,&b,&c);
if((a>-EXP)&&(a<EXP))//判断a=0
{
printf("不是一元二次方程组\n");
}
else
{
double disc = b*b-4*a*c;
if(disc<0)
printf("无解\n");
else if(disc>-EXP&&disc<EXP)
{
printf("%lf\n", (-b)/(2*a));
}
else if(disc>0.0)
{
printf("x1 = %lf\n", (-b+sqrt(disc))/(2*a));
printf("x2 = %lf\n", (-b-sqrt(disc))/(2*a));
}
else
{
printf("无解\n");
}
}
return 0;
}
用c语言求解一元二次方程
最新推荐文章于 2024-06-17 00:58:23 发布