求ax的2次方+bx+c=0的方程解,而且b的2次方-4ac>0,a,b,c由键盘输入要求尽量简单,简洁,我是菜鸟,太复杂看不懂,

问题描述:

求ax的2次方+bx+c=0的方程解,而且b的2次方-4ac>0,a,b,c由键盘输入
要求尽量简单,简洁,我是菜鸟,太复杂看不懂,

#include
#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);//调用求根函数
}