// 求方程式 ax^2+bx+c=0 的根,分别考虑:1、有两个不等的实根 2、有两个相等的实根 #include <stdio.h> #include <math.h> 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\n",x,y); } else if( d == 0 ) { x = ( ( -1 ) * b ) / ( 2 * a ); printf("此方程只有一个实根:x = y = %f\n",x); } else printf("此方程没有实根\n"); return 0; } <img src="http://img.blog.csdn.net/20150423115503455?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> <img src="http://img.blog.csdn.net/20150423115509602?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> <img src="http://img.blog.csdn.net/20150423115630916?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
时间: 2024-10-10 21:58:20