# include <stdio.h>
# include <math.h>
int main(void)
{
int a = 1;
int b = 2;
int c = 3;
double delta;
double x1;
double x2;
delta = b*b-4*a*c;
if (delta > 0 )
{
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
printf("该一元二次方程有两个实数解,1=%f,x2=%f\n",x1,x2);
}
else if (delta == 0)
{
x1 = (-b)/(2*a);
x1 = x2;
printf("该一元二次方程有一个唯一解,x1=x2=%f\n",x1);
}
else
printf("该一元二次方程无解\n");
return 0;
}
这是我调得!
你的问题:多注意一下输入时中英文的切换,
错误我在你的代码上注释出来了!
# include <stdio.h>
# include <math.h>
int main(void)
{
//花括号是中文状态的
int a = 1;
int b = 2;
int c = 3;
double delta;
double x1;
double x2;
delta = b*b-4*a*C;
if (delta > 0 )
{
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
printf("该一元二次方程有两个实数解,x1=%f,x2=%f\n",x1,x2,);//最后x2后面应该没有“,”;
}
else if (delta == 0)
{
x1 = (-b)/(2*a);
x1 = x2;
printf("该一元二次方程有一个唯一解,x1=x2=%f\n",x1);
}
else
{
printf("该一元二次方程无解\n");
}
return o;//返回值应该是0,而不是小写字母o;
}
多注意一下输入时中英文的切换