c语言 编程 求方程ax2+bx+c=0的根,用三个函数分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果.#include#includevoid deltaZero(double a,double b,double c){double ans=-b/(2*a);printf("x1=x2=%lf\n",ans);}void deltaLargerZ
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 13:50:24
c语言 编程 求方程ax2+bx+c=0的根,用三个函数分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果.#include#includevoid deltaZero(double a,double b,double c){double ans=-b/(2*a);printf("x1=x2=%lf\n",ans);}void deltaLargerZ
c语言 编程 求方程ax2+bx+c=0的根,用三个函数分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果.
#include
#include
void deltaZero(double a,double b,double c)
{
double ans=-b/(2*a);
printf("x1=x2=%lf\n",ans);
}
void deltaLargerZero(double a,double b,double c)
{
double ans1,ans2,d;
\x05d=b*b-4*a*c;
ans1 = (-b+sqrt(d))/(2*a);
ans2 = (-b-sqrt(d))/(2*a);
printf("x1=%lf,x2=%lf\n",ans1,ans2);
}
void deltaLessZero(double a,double b,double c)
{
double real,imar,d;
\x05d=b*b-4*a*c;
real = -b/(2*a);
imar = sqrt(-d)/(2*a);
printf("x1=%lf+%lfi,x2=%lf-%lfi\n",real,imar,real,imar);
}
void main()
{
double a,b,c;
\x05double d;
printf("please input a,b,c\n");
scanf("%lf,%lf,%lf",&a,&b,&c);
d=b*b-4*a*c;
if(d==0) deltaZero(a,b,c);
else if(d>0) deltaLargerZero(a,b,c);
else if(d
c语言 编程 求方程ax2+bx+c=0的根,用三个函数分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果.#include#includevoid deltaZero(double a,double b,double c){double ans=-b/(2*a);printf("x1=x2=%lf\n",ans);}void deltaLargerZ
是否是输入的问题?
scanf("%lf,%lf,%lf",&a,&b,&c);中使用了通配符',',输入的时候也要按原格式输入.
也可以改为scanf("%lf%lf%lf",&a,&b,&c);则空格回车都可作间隔符.