求个会C语言的哥哥姐姐解答

来源:百度知道 编辑:UC知道 时间:2024/05/16 18:33:16
ax的平方+bx+c=0,b的平方-4ac大于0,且a不为0,求源代码。

#include "stdio.h"
#include "math.h"
void main()
{ double a,b,c;
double x1,x2,D,D2;
printf("enter three number:");
scanf("%lf %lf %lf",&a,&b,&c);
printf("\n%.0lfx^2+%.0lfx+%.0lf=0\n",a,b,c);
D2=pow(b,2)-4*a*c;
D=sqrt(D2);
x1=(-b+D)/2*a; x2=(-b-D)/2*a;
if(a==0)
if(b==0) printf("you enter number is wrong.\n");
else { x1=x2=-c/b; printf("x1=x2=%lf",x1); }
else if(D2>0) { x1=(-b+D)/2*a; x2=(-b-D)/2*a;
printf("x1=%lf x2=%lf",x1,x2);}
else if(D2==0) { x1=x2=-b/2*a;
printf("x1=%lf x2=%lf",x1,x2);}
else printf("you enter number is wrong.\n");
}

a*x*x+b*x+c=0&&b*b-4*a*c>0&&a!=0