#include #include main() { float a,b,c,x1,x2,d; scanf("%f %f %f\n",&a,&b,&c); d=b*#include#includemain(){float a,b,c,x1,x2,d;scanf("%f %f %f\n",&a,&b,&c);d=b*b-4*a*c;if(d>=0 )if(d==0 ){ x1=x2=-b/(2*a);printf("x1=x2=%f\n",x1);}else{ x1=(-b+sqrt(d))/(2
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/29 03:43:28
![#include #include main() { float a,b,c,x1,x2,d; scanf(](/uploads/image/z/2724496-16-6.jpg?t=%23include+%23include+main%28%29+%7B+float+a%2Cb%2Cc%2Cx1%2Cx2%2Cd%3B+scanf%28%22%25f+%25f+%25f%5Cn%22%2C%26a%2C%26b%2C%26c%29%3B+d%3Db%2A%23include%23includemain%28%29%7Bfloat+a%2Cb%2Cc%2Cx1%2Cx2%2Cd%3Bscanf%28%22%25f+%25f+%25f%5Cn%22%2C%26a%2C%26b%2C%26c%29%3Bd%3Db%2Ab-4%2Aa%2Ac%3Bif%28d%3E%3D0+%29if%28d%3D%3D0+%29%7B+x1%3Dx2%3D-b%2F%282%2Aa%29%3Bprintf%28%22x1%3Dx2%3D%25f%5Cn%22%2Cx1%29%3B%7Delse%7B+x1%3D%28-b%2Bsqrt%28d%29%29%2F%282)
#include #include main() { float a,b,c,x1,x2,d; scanf("%f %f %f\n",&a,&b,&c); d=b*#include#includemain(){float a,b,c,x1,x2,d;scanf("%f %f %f\n",&a,&b,&c);d=b*b-4*a*c;if(d>=0 )if(d==0 ){ x1=x2=-b/(2*a);printf("x1=x2=%f\n",x1);}else{ x1=(-b+sqrt(d))/(2
#include #include main() { float a,b,c,x1,x2,d; scanf("%f %f %f\n",&a,&b,&c); d=b*
#include
#include
main()
{
float a,b,c,x1,x2,d;
scanf("%f %f %f\n",&a,&b,&c);
d=b*b-4*a*c;
if(d>=0 )
if(d==0 )
{ x1=x2=-b/(2*a);
printf("x1=x2=%f\n",x1);
}
else
{ x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
}
else
{
printf("无解\n");
}
错在哪里
#include #include main() { float a,b,c,x1,x2,d; scanf("%f %f %f\n",&a,&b,&c); d=b*#include#includemain(){float a,b,c,x1,x2,d;scanf("%f %f %f\n",&a,&b,&c);d=b*b-4*a*c;if(d>=0 )if(d==0 ){ x1=x2=-b/(2*a);printf("x1=x2=%f\n",x1);}else{ x1=(-b+sqrt(d))/(2
主要问题是最后少了一个大括号
另外写程序要养成良好的习惯:
每个函数都最好要有返回值;
没个函数都要有参数,无参数的要加void;
变量定义和可执行语句最好分开写;
要有提示用户输入的语句;
输入方式要友好;
逻辑结构要明显;
.
当然标准的函数还要有函数说明的.
#include
#include
int main(void)
{
float a,b,c,x1,x2,d;
printf("请输入方程ax^2+bx+c=0中的参数a,b和c,并以逗号隔开!\n");
printf("a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
d=b*b-4*a*c;
if(d>=0 )
if(d==0 )
{
x1=x2=-b/(2*a);
printf("x1=x2=%f\n",x1);
}
else
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%f,x2=%f\n",x1,x2);
}
else
{
printf("无解\n");
}
return 0;
}