c 程序 :求方程ax2+bx+c=0的根,用三个函数分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果.
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,x;
\x05double d;
printf("please input a,b,c:");
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
主函数中加个if条件判断啦!
if(a==0)
\x09{
\x09\x09if(b==0)\x09printf("ERROR!\n");
\x09\x09else\x09\x09printf("x=%.2lf\n",-c/b);
\x09}
\x09else{
d=b*b-4*a*c;
if(d==0) deltaZero(a,b,c);
else if(d>0) deltaLargerZero(a,b,c);
else if(d