新手学习:一元二次方程代码不知道问题在哪里?
程序代码:
# include <stdio.h> # include <math.h> int main(void) { double a, b, c; double delta; double x1, x2; char ch; printf("输入方程的系数:\n"); printf("a = "); scanf("%lf", &a); printf("b = "); scanf("%lf", &b); printf("c = "); scanf("%lf", &c); delta =b*b-4*a*c; if (delta > 0) { x1 = (-b+sqrt(delta))/(2*a); x2 = (-b-sqrt(delta))/(2*a); printf("有两个答案, x1 = %lf , x2 = %lf\n", x1, x2); } else if (delta == 0);//这里多了一个分号 { x1 = x2 = (-b)/(2*a); printf("唯一答案, x1 = x2 %lf\n", x1 ,x2); } else { printf("无答案\n"); } return 0; }
[此贴子已经被作者于2016-4-22 17:56编辑过]