大神再帮我看看,c语言的小问题
为什么我输什么系数进去都说方程无解啊? 看我写的代码,好好看,好好看:# include <stdio.h>
# include <math.h>
int main()
{
double a;
double b;
double c;
double delta;
double x1;
double x2;
printf("请输入系数a: ");
scanf("%lf", &a);
printf("请输入系数b: ");
scanf("%lf", &b);
printf("请输入系数c: ");
scanf("%lf", &c);
delta = b*b -4*a*c;
if (delta>0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("该一元二次方程有两个解: x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (delta==0)
{
x1 = (-b) /(2*a);
x2 = x1;
printf("该一元二次方程有唯一解: x1 = x2 = %lf\n", x1);
}
else
{
printf("该一元二次方程无解!\n");
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main(void)
{
int a, b, c;
double delta, x1, x2;
printf("系数a:");
scanf("%d",&a);
printf("系数b:");
scanf("%d",&b);
printf("系数c:");
scanf("%d",&c);
delta = b*b - 4*a*c;
if(delta > 0)
{
x1 = (-b + sqrt(delta))/(2*a);
x2 = (-b - sqrt(delta))/(2*a);
printf("该一元二次方程有两个解:x1 = %lf, x2 = %lf\n", x1, x2);
}else if(delta == 0)
{
x1 = -b/(2 * a);
x2 = x1;
printf("该一元二次方程有一个解:x1 = x2 = %lf\n", x1);
}else
{
printf("该一元二次方程无解!");
}
return 0;
}
我的貌似也没事。。。
页:
[1]