读书人

C语言菜鸟举手提问高手老师实例异常

发布时间: 2012-02-05 12:07:15 作者: rapoo

C语言初学者举手提问高手老师请指教实例错误~
/* 以下输入三个实数代入a*x*x+b*x+c=0求一元二次方程式根
编译时候出现6个错误,不知道如何改正和错误之处。。。希望高手老师指点讲解并改正出。。。谢谢~谢谢~谢谢~谢谢。。 */
#include "stdio.h "
main()
{
void solving_quadratic_equa(float a,float b,float c,)
float A,B,C;
printf( "Enter three numbers for a b c in the quadratic equation:\n ");
scanf( "%f%f%f ",&A,&B,&C);
solving_quadratic_equa(float A,float B,float C);

}
#include "math.h "
void solving_quadratic_equa(float a,float b,float c)
{
if(a==0.0)
if(b==0.0)
printf( "no answer due to input error.\n ");
else
printf( "the single root is %f.\n ",-c/b);
else
{
double disc,twoa,term1,term2;
disc=b*b-4*a*c;
twoa=2*a;
term1=-b/twoa;
term2=sqrt(fabs(disc))/twoa;
if(disc <0.0)
printf( "complex root:\nreal part=%f,imag part=%f\n ",term1,term2);
else
printf( "real root:\nroot1=%f,root2=%f\n ",term1-term2,term1+term2);
}
}

[解决办法]
#include "stdio.h "
#include "math.h "
void main(void)
{
void solving_quadratic_equa(float a,float b,float c);
float A,B,C;
printf( "Enter three numbers for a b c in the quadratic equation:\n ");
scanf( "%f%f%f ",&A,&B,&C);
solving_quadratic_equa(A,B,C);

getchar();
}
#include "math.h "
void solving_quadratic_equa(float a,float b,float c)
{
if(fabs(a) <0.0001)
if(fabs(b) <0.0001)
printf( "no answer due to input error.\n ");
else
printf( "the single root is %f.\n ",-c/b);
else
{
double disc,twoa,term1,term2;
disc=b*b-4*a*c;
twoa=2*a;
term1=-b/twoa;
term2=sqrt(fabs(disc))/twoa;
if(disc <0.0)
printf( "complex root:\nreal part=%f,imag part=%f\n ",term1,term2);
else
printf( "real root:\nroot1=%f,root2=%f\n ",term1-term2,term1+term2);
}
}

读书人网 >C语言

热点推荐