c语言 一元二次方程求根 哪错了?

来源:百度知道 编辑:UC知道 时间:2024/06/24 12:13:59
#include <stdio.h>
#include <math.h>

int ercifangcheng(float a,float b,float c);

int main(void)
{
float x,y,z;
printf("please input the numbers:");
scanf("%f%f%f",&x,&y,&z);
ercifangcheng(x,y,z);
return 0;
}

int ercifangcheng(float a,float b,float c)
{
double disc,term1,term2,term;
disc=b*b-4ac;
term=sqrt(fabs(disc));
term1=-b/2a;
term2=term/2a;

if (a==0)
{
if(b==0)
printf("NO roots!\n");
else
printf("root1=root2=%f.\n",-c/b);
}
else
{
if(disc<0)
printf("root1=%fi,root2=%fi\n",term1+term2,term1-term2);
else
printf("root1=%f,root2=%f\n",term1+term2,term1-term2);
}
return 0;
}


#include <stdio.h>
#include <math.h>

int ercifangcheng(float a,float b,float c);

int main(void)
{
float x,y,z;
printf("please input the numbers:");
scanf("%f%f%f",&x,&y,&z);
ercifangcheng(x,y,z);
return 0;
}

int ercifangcheng(float a,float b,float c)
{
double disc,term1,term2,term;
disc=b*b-4*a*c;
term=sqrt(fabs(disc));
term1=-b/(2*a);
term2=term/(2*a);

if (a==0)
{
if(b==0)
printf("NO roots!\n");
else
printf("root1=root2=%f.\n",-c/b);
}
else
{
if(disc<0)
printf("root1=%fi,root2=%fi\n",term1+term2,term1-term2);
else
printf("root1=%f,root2=%f\n",term1+term2,term1-term2);
}
return 0;
}