当前位置: 代码迷 >> C语言 >> [求助]大家帮我看看,为什么这个程序不能执行
  详细解决方案

[求助]大家帮我看看,为什么这个程序不能执行

热度:231   发布时间:2005-06-04 09:03:00.0
[求助]大家帮我看看,为什么这个程序不能执行

大家好,有个程序其代码如下:

#include <math.h> float x1,x2,disc,p,q; greater_than_zero(float a,float b) {x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); } equal_than_zero(float a,float b) { x1=x2=(-b)/(2*a); } smaller_than_zero(float a,float b) { p=(-b)/(2*a>; q=sqrt(disc)/(2*a); } main() { float a,b,c; printf("\nInput a,b,c:"); scanf("%f,%f,%f",&a,&b,&c); printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c); disc=b*b-4*a*c; printf("root:\n"); if (disc>0) { greater_than_zero(a,b); printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2); } else if (disc=0) {equal_than_zero(a,b); printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2); } else {smaller_than_zero(a,b); printf("x1=%5.2f+%5.2fi\tx2=%5.2f-%5.2fi\n",p,q,p,q); } }

为什么最后在运行的时候会出现如图的提示啊,请高手教教我,不胜感激!!!

谢谢大家!!

搜索更多相关的解决方案: float  disc  zero  

----------------解决方案--------------------------------------------------------
图:
#include &lt;math.h&gt;
float x1,x2,disc,p,q;
greater_than_zero(float a,float b)
{x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
}
equal_than_zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}
smaller_than_zero(float a,float b)
{
p=(-b)/(2*a&gt;;
q=sqrt(disc)/(2*a);
}
main()
{
float a,b,c;
printf("\nInput a,b,c:");
scanf("%f,%f,%f",&amp;a,&amp;b,&amp;c);
printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c);
disc=b*b-4*a*c;
printf("root:\n");
if (disc&gt;0)
{
greater_than_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
}
else if (disc=0)
  {equal_than_zero(a,b);
  printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2);
  }
  else
  {smaller_than_zero(a,b);
  printf("x1=%5.2f+%5.2fi\tx2=%5.2f-%5.2fi\n",p,q,p,q);
  }
}
----------------解决方案--------------------------------------------------------
图开如下:

----------------解决方案--------------------------------------------------------
功能函数smaller_than_zero有语法错误
----------------解决方案--------------------------------------------------------
以下是引用梦幻之人在2005-6-4 9:06:13的发言: #include <math.h> float x1,x2,disc,p,q; greater_than_zero(float a,float b) {x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); } equal_than_zero(float a,float b) { x1=x2=(-b)/(2*a); } smaller_than_zero(float a,float b) { p=(-b)/(2*a>; //改成p=(-b)/(2*a); q=sqrt(disc)/(2*a); } main() { float a,b,c; printf("\nInput a,b,c:"); scanf("%f,%f,%f",&a,&b,&c); printf("\nequation:%5.2f*x*x+%5.2f*x+%5.2f=0\n",a,b,c); disc=b*b-4*a*c; printf("root:\n"); if (disc>0) { greater_than_zero(a,b); printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2); } else if (disc=0) {equal_than_zero(a,b); printf("x1=%5.2f\tx2=%5.2f\n\n",x1,x2); } else {smaller_than_zero(a,b); printf("x1=%5.2f+%5.2fi\tx2=%5.2f-%5.2fi\n",p,q,p,q); } }

----------------解决方案--------------------------------------------------------
  相关解决方案