作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/30 05:01:55
求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);//调用求根函数
}