c语言高手,帮个忙?

来源:百度知道 编辑:UC知道 时间:2024/05/23 12:39:21
求方程ax2+bx+c=0的根,用3个函数分别求当b2-4ac大于0,等于零,小于0时的根并输出结果.从主函数输入a'b'c的值.
回答者:leekumbong - 秀才 三级,这位大哥,你这次的程序有两个警告,但是可以运行,就是.......好像结果...不是很正确啊......

你试试这个行不行
/*********************
#include <math.h>
#include <stdio.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_to_zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}

smaller_than_zero(float a,float b)
{
p=-b/(2*a);
q=sqrt(abs(disc))/(2*a);
}

int main(int argc, char* argv[])
{
float a,b,c;
printf("Input 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_to_zero(a,b);
printf("x1=%5.2f\tx2=%5.2f\n\n&qu