C++运算函数问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 04:47:21
return((pow(i,(1/2))*pow(((b+m*h)*h),(5/3)))/(n*pow((b+2*h*pow((1+m*m),(1/2))),(2/3))) -Q) ;// 函数f(h) 公式截图
上面这个 运算函数好象有点问题 编译没有问题 就是运行不出来 -------------------------------------------------------- #include"iostream" #include"iostream.h" #include"stdio.h" #include"math.h" #define null 0 double fh(double),n,b,m,i,Q ; //f(x)函数 及其变量的声明 void main() { double xa(null),xb(null),xc(null),n(null),b(null),m(null),i(null),Q(null); do { printf("请输入一个范围:最小值 最大值 n,b,m,i,Q :"); std::cin>>xa>>xb>>n>>b>>m>>i>>Q; //输入xa xb a 的值 printf("%f %f %f %f %f %f %f",xa,xb,n,b,m,i,Q); } while(fh(xa)*fh(xb)>=0); //判断输入范围内是否包含函数值0 do { if(fh((xc=(xa+xb)/2))*fh(xb){ xa=xc; } else { xb=xc; } } while(fh(xc)>pow(10.0,-5)||fh(xc)printf("\n\n\n 得数为:%f \n\n\n",xc); } double fh(double h) { return((pow(i,(1/2))*pow(((b+m*h)*h),(5/3)))/(n*pow((b+2*h*pow((1+m*m),(1/2))),(2/3))) -Q)

全局变量n,b,m,i,Q在主函数中被屏蔽掉了,
这样函数fh()得不到正确的n,b,m,i,Q数据,所以错误
解决方法,主函数中的定义
double xa(null),xb(null),xc(null),n(null),b(null),m(null),i(null),Q(null);
改为
double xa(null),xb(null),xc(null);
另外,1/2=0,所以不能用1/2,改为0.5,5/3要改成5.0/3.0,2/3改成2.0/3.0,这样就OK了

没问题啊,编译通过了啊
#include "stdafx.h"
#include<iostream>
using namespace std;

class point
{
public :
point(int xx=0,int yy=0)
{
X=xx;
Y=yy;
}

point(point &p);

int GetX() {return X;}
int GetY() {return Y;}

private :
int X,Y;
};

point::point(point &p)
{
X=p.X;
Y=p.Y;
cout<<"构造函数被调用"<<endl;
}

void fun1(point p)
{
cout<<p.GetX()<<endl;
}

point fun2()
{
point A(1,2);
return A;
}

int main()
{
point A(4,5);
point B(