该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
int main (void)
{
double a, b , c ;
double x1 , x2 ;
double d ;
printf("a = ");
scanf("%lf",&a);
printf("b = ");
scanf("%lf",&b);
printf("c = ");
scanf("%lf",&c);
detla = (b*b) - (4*a*c);
if(0 == detla)
{
x1 = x2 =(-b)/(2*a);
printf("有唯一解\n x1 = x2 = %lf",x1 , x2 );
}
else if (d > 0)
{
x1 = ((-b)+sqrt(detla))/(2*a);
x2 = ((-b)-sqrt(detla))/(2*a);
printf("有两解\n x1 = %lf x2 = %lf", x1 , x2 );
}
else
{
printf("无解\n");
}
return 0 ;
}
这个detla赋值在scanf的后面程序是对的
#include
#include
int main (void)
{
double a, b , c ;
double x1 , x2 ;
double d ;
detla = (b*b) - (4*a*c);
printf("a = ");
scanf("%lf",&a);
printf("b = ");
scanf("%lf",&b);
printf("c = ");
scanf("%lf",&c);
if(0 == detla)
{
x1 = x2 =(-b)/(2*a);
printf("有唯一解\n x1 = x2 = %lf",x1 , x2 );
}
else if (d > 0)
{
x1 = ((-b)+sqrt(detla))/(2*a);
x2 = ((-b)-sqrt(detla))/(2*a);
printf("有两解\n x1 = %lf x2 = %lf", x1 , x2 );
}
else
{
printf("无解\n");
}
return 0 ;
}
这个detla在前面不管什么都是无解,到底是为什么啊