菜鸡编译的一元二次方程报错。
# include <stdio.h>int main(void)
{
//把3个系数保存在电脑中
int a = 1; //=不表示相等,表示赋值
int b = 2;
int c = 3;
double delta; //delta存放的是 b*b - 4*a*c
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("该一元二次方程有2个解,x1 = %f, x2 = %f\n", x1, x2);
}
else if (delta = 0)
{
x1 = (-b) / (2*a);
x2 = x1; //右边赋给左边
printf("该一元二次方程有1个解, x1 = x2 = %f\n", x1, x2);
}
else
{
printf("无解");
}
return 0;
}