求助:有关C语言的问题!

编程菜菜鸟求助:
我要编一个解二元一次的方程程序,原式如下:
// 一元二次函数求根.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "math.h"
#include "iostream.h"
float fac(float a,float b,float c)
{ float s;
s=b*b-4*a*c;
return c;
}
float xa(float a,float b,float c)
{
float x;
x=(-b+sqrt(b*b-4*a*c))/(2*a);
return x;
}
float xb(float a,float b,float c)
{
float y;
y=(-b-sqrt(b*b-4*a*c))/(2*a);
return y;
}
void main()
{
float m,n,z,a,b,c
;
cout<<"请输入a,b,c的值!"<<endl;
cin>>a>>b>>c;
z=fac(a,b,c);
m=xa(a,b,c);
n=xb(a,b,c);
if (z<0)
cout <<"该方程不存在实数根!"<<endl;
else if (z>0||z==0)
cout<<"x1="<<m<<";x2="<<n<<endl;
}
运行后,输入一个a,b,c值,使得△<0,按理应显示"该方程不存在实数根!"可事实上却显示“x1=-1.#IND;x2=-1.#IND”
请问各位大虾应如何修改!谢谢。

第1个回答  2007-06-16
// fd.cpp : Defines the entry point for the console application.
//FAC函数的返回值错误。。应返回S。

#include "stdafx.h"
#include "math.h"
#include "iostream.h"
float fac(float a,float b,float c)
{ float s;
s=b*b-4*a*c;
return s;
}
float xa(float a,float b,float c)
{
float x;
x=(-b+sqrt(b*b-4*a*c))/(2*a);
return x;
}
float xb(float a,float b,float c)
{
float y;
y=(-b-sqrt(b*b-4*a*c))/(2*a);
return y;
}

void main()
{
float m,n,z,a,b,c ;
cout<<"请输入a,b,c的值!"<<endl;
cin>>a>>b>>c;
z=fac(a,b,c);
m=xa(a,b,c);
n=xb(a,b,c);
if (z<0)
cout <<"该方程不存在实数根!"<<endl;
else
cout<<"x1="<<m<<";x2="<<n<<endl;
}本回答被提问者采纳
第2个回答  2007-06-16
我觉得也是
相似回答