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

来源:百度知道 编辑:UC知道 时间:2024/05/21 08:17:04
编程菜菜鸟求助:
我要编一个解二元一次的方程程序,原式如下:
// 一元二次函数求根.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

// 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;
}

我觉得也是