啊哈磊_编程从这里起步
标题:
报错“else”without a previous"if"
[打印本页]
作者:
pompeii
时间:
2020-9-21 16:45
标题:
报错“else”without a previous"if"
# 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",x1,x2);
}
else if (delta==0)
{
x1=(-b)/(2*a);
x2=x1;
printf("该方程有唯一解,x1=x2=%f",x1,x2);
}
else
{
printf("无解");
}
return 0;
}
复制代码
欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/)
Powered by Discuz! X3.2