# include <stdio.h>
# include <math.h>
int main(void)
{
int a, b, c;
printf("请输入三个系数,用逗号分开:");
scanf("a = %f, b = %f, c = %f",&a , &b , &c);
double delta;
double x1;
double x2;
delta = (b*b) - (4*a*c);
if (delta<0)
{
printf("该方程没有实数解\n");
}
else if(delta > 0)
{
x1 = ( (-b) + sqrt (delta) ) / (2*a);
x2 = ( (-b) + sqrt (delta) ) / (2*a);
printf("x1 = %f, x2 = %f\n",x1, x2);
}
else if(delta = 0)
{
x1 = (-b) / (2*a);
x2 = x1;
printf("x1 = x2 =%f\n",x1);
}
return 0;
}
这个求一元二次方程输入一些有解的数可是 运行后却显示无解,我感觉问题出在scanf("a = %f, b = %f, c = %f",&a , &b , &c); 网上搜了好久都找不到和我一样路子的,到底问题出在哪里,求解
# include <math.h>
int main(void)
{
int a, b, c;
printf("请输入三个系数,用逗号分开:");
scanf("a = %f, b = %f, c = %f",&a , &b , &c);
double delta;
double x1;
double x2;
delta = (b*b) - (4*a*c);
if (delta<0)
{
printf("该方程没有实数解\n");
}
else if(delta > 0)
{
x1 = ( (-b) + sqrt (delta) ) / (2*a);
x2 = ( (-b) + sqrt (delta) ) / (2*a);
printf("x1 = %f, x2 = %f\n",x1, x2);
}
else if(delta = 0)
{
x1 = (-b) / (2*a);
x2 = x1;
printf("x1 = x2 =%f\n",x1);
}
return 0;
}
这个求一元二次方程输入一些有解的数可是 运行后却显示无解,我感觉问题出在scanf("a = %f, b = %f, c = %f",&a , &b , &c); 网上搜了好久都找不到和我一样路子的,到底问题出在哪里,求解