一元二次方程求解的问题
程序代码:
# include <stdio.h> # include <math.h> int main(void) { double a, b, c, disc, x1, x2; printf("求解一元二次方程\n"); printf("请输入a b c的值:\n"); scanf("%lf %lf %lf", &a, &b, &c); disc = sqrt(b*b - 4*a*c); if (a<=0)//这里合适么? printf("这不是一元二次方程\n"); else { if (sqrt<0)//这里合适么? printf("方程无实根\n"); else if (sqrt>0)//同上 { x1 = ((-b)+disc)/(2*a); x2 = ((-b)-disc)/(2*a); printf("方程两实根分别为:\nx1=%.2lf, x2=%.2lf\n", x1, x2); } else { x1 = ((-b)+disc)/(2*a); x2 = x1; printf("方程有一个实根:\nx1=x2=%.2lf\n", x1); } } return 0; }