回复 楼主 seep666
#include<stdio.h>
#include<math.h>
int main(viod)
{ /*声明变量a b c并初始化*/
float a=0.0f;
float b=0.0f;
float c=0.0f;
/*用来存储b*b-4*a*c */
float data=0.0f;
/*用来存储两个不同的实根*/
float root1=0.0f,root2=0.0f;
/*用来存储虚根的 实部 和 虚部*/
float realpart=0.0f;
float imagpart=0.0f;
loop: printf("Please Enter The Value Of a b c:\n");
scanf("%f ,%f, %f",&a,&b,&c);
/*当a=0时*/
if(fabs(a)<1e-5)
/*如果b=0*/
if(fabs(b)<1e-5)
{
printf("\nIt Is Error, Please Enter Again!\a\a\a");
goto loop;
}
else
/*如果b不等于0时输出 -c/b的值*/
printf("\nThe Function Has A Special Root,Is: %.2f.",-c/b);
else
{ data=pow(b,2)-4*a*c;
if(data>1e-5)
/*当b*b-4*a*c>0时 方程有两个不等的实根*/
{ printf("The Function Has Two Real Roots");
root1=(-b+sqrt(data))/(2*a);
root2=(-b+sqrt(data))/(2*a);
printf(" They Are x1=%.2f And x2=%.2f.",root1,root2);}
/*当b*b-4*a*c=0时方程有两个相等的实根*/
else
if(data==0)
printf("There Are Two Equal Roots:x1=x2=%.2f."-b/(2*a));
/*当 b*b-4*a*c<0时方程有两个虚根*/
else
{ printf("The Function Has Two Imaginary Roots");
realpart=-b/(2*a);
imagpart=sqrt(-data)/(2*a);
printf(" They Are x1=%.2f+%.2fi And x2=%.2f-%.2fi.",
realpart,imagpart,realpart,imagpart);}
}
return 0;
}
由于时间仓促此程序未经测试,请自己试一下吧!如有建议可以给我发邮件。邮箱situjinxian@
[
本帖最后由 司徒瑾贤 于 2010-3-19 15:39 编辑 ]