求ax的2次方+bx+c=0的方程解,而且b的2次方-4ac>0,a,b,c由键盘输入

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:10:01
要求尽量简单,简洁,我是菜鸟,太复杂看不懂,谢谢

#include<stdio.h>
#include"math.h"
void seekroot (float a,float b,float c) //求根函数
{
float m,term1,term2;
if(a==0)
if(b==0)
printf("the answer not exist.\n");
else printf("the answer is %f\n",-c/b);
else
{
m=b*b-4*a*c;
if(m>0)
{

term1=(-b+sqrt(m))/(2*a);
term2=(-b-sqrt(m))/(2*a);
printf("the root is %f and %f",term1,term2);}

else printf("the real root not exsit !\n");
}
}
main()
{
float d,e,f;
printf("please input three numbers;\n");
scanf("%f%f%f",&d,&e,&f);
seekroot(d,e,f);//调用求根函数

}

printf("%f",(-b*sqrt(b*b-4.0*a*c))/(2.0*a));