如何用C++求解方程ax^2+bx+c=0的解
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/26 04:20:04
如何用C++求解方程ax^2+bx+c=0的解
#include
#include
class Equation{
\x05float a,b,c;
\x05
public:
\x05float x[2];
\x05Equation(float a1=0.0,float b1=0.0,float c1=0.0)
\x05{
\x05\x05a=a1;
\x05\x05b=b1;
\x05\x05c=c1;
\x05}
\x05~Equation(){}
\x05long CalResult();
\x05
};
long Equation::CalResult()
{
\x05long temp;
\x05if ((b*b-4*a*c)==0)
\x05{
\x05\x05temp=1;
\x05\x05x[0]=(float)(-(b/2*a));
\x05\x05return temp;
\x05}
\x05if ((b*b-4*a*c)>0)
\x05{
\x05\x05temp=2;
\x05\x05x[0]=(-b+sqrt(b*b-4*a*c))/(2*a);
x[1]=(-b-sqrt(b*b-4*a*c))/(2*a);
\x05\x05return temp;
\x05}
\x05else
\x05{
\x05\x05temp=0;
\x05}
\x05return temp;
}
int main()
{
\x05float a,b,c;
\x05char ch;
\x05do{
\x05\x05cout
#include
class Equation{
\x05float a,b,c;
\x05
public:
\x05float x[2];
\x05Equation(float a1=0.0,float b1=0.0,float c1=0.0)
\x05{
\x05\x05a=a1;
\x05\x05b=b1;
\x05\x05c=c1;
\x05}
\x05~Equation(){}
\x05long CalResult();
\x05
};
long Equation::CalResult()
{
\x05long temp;
\x05if ((b*b-4*a*c)==0)
\x05{
\x05\x05temp=1;
\x05\x05x[0]=(float)(-(b/2*a));
\x05\x05return temp;
\x05}
\x05if ((b*b-4*a*c)>0)
\x05{
\x05\x05temp=2;
\x05\x05x[0]=(-b+sqrt(b*b-4*a*c))/(2*a);
x[1]=(-b-sqrt(b*b-4*a*c))/(2*a);
\x05\x05return temp;
\x05}
\x05else
\x05{
\x05\x05temp=0;
\x05}
\x05return temp;
}
int main()
{
\x05float a,b,c;
\x05char ch;
\x05do{
\x05\x05cout
如何用Matlab求sin(bx)exp(ax)-c=0的解?
已知一个方程ax^2+bx=c=0,如何利用abc求解
二次函数y=ax*2+bx+c(a≠0)图像如图那么关于x方程ax*2+bx+c根的情况
方程ax^2+bx+c=0(a>0)有两实根,分别为3,-4,则不等式ax^2+bx+c>0的解集为
已知关于x的一元二次方程ax^2+bx+c=0 求解?
用MATLAB求解一元二次方程ax^2 +bx+c=0的根
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序
C语言 求方程 ax^2+bx+c=0的根
已知抛物线y=ax^2+bx+c如图,方程ax^2+bx+c=k没有实数根,则k的取值范围是
已知方程x^3+ax^2+bx+c=0
如何用C语言计算一个函数的值,比如说F(x)=ax平方+bx+c,
matlab中怎样编写求解方程ax^2+bx+c=0的根的函数,这里应根据b^2-4ac的不同取值分