...求ax的平方+bx+c=0方程的根,a,b,c由键盘输入,设b的平方-4ac>0_百 ...
发布网友
发布时间:2024-12-04 15:11
我来回答
共1个回答
热心网友
时间:2024-12-19 04:15
#include "stdio.h"
#include "math.h"
main()
{
double a,b,c,x1,x2,dt,p,q;
printf("please input a,b,c:");
scanf("%lf%lf%lf",&a,&b,&c);
if(b*b-4*a*c>=0)
{
dt=sqrt(b*b-4*a*c);
p=-b/(2*a);
q=dt/(2*a);
x1=p+q;
x2=p-q;
printf("the root of equation%6.2fx*x+%6.2fx+%6.2f=0 is\n",a,b,c);
printf("x1=%6.2f x2=%6.2f\n",x1,x2);
}
else
printf("the root of equation%6.2fx*x+%6.2fx+%6.2f=0 is none.\n",a,b,c);
}