// 求方程式 ax^2+bx+c=0 的根,分别考虑:1、有两个不等的实根 2、有两个相等的实根 #include #include int main() { int d; int a,b,c; double x,y; double f; printf("请输入a,b,c:"); scanf("%d%d%d",&a,&b,&c); d = b*b-4*a*c; f = sqrt(d); if( d > 0) { x = ( ( -1 ) * b + f ) / ( 2 * a ); y =( ( -1 ) * b - f ) / ( 2 * a ); printf("有两个实根:x = %f y = %f
",x,y); } else if( d == 0 ) { x = ( ( -1 ) * b ) / ( 2 * a ); printf("此方程只有一个实根:x = y = %f
",x); } else printf("此方程没有实根
"); return 0; }