编程菜菜鸟求助:
我要编一个解二元一次的方程程序,原式如下:
// 一元二次函数求根.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”
请问各位大虾应如何修改!谢谢。