老T请解释下面现象:
到底是C++就是不一样,循环次数再多也累不死!
这是我的代码,请老T检查一下有没有不妥的地方(ea ,eb均是图中所示的位置,只不过高度自定)
#include <iostream>
#include <string>
# include <cmath>
void main()
{
using std::cin;
using std::cout;
using std::string;
using std::endl;
double y ,ea, eb ;
double eax=0, eay=0,ebx=0,eby=0;
double m , n,q;
q=1;
cout<<"请输入高度"<<endl;
while(cin>>y )
{
double eax=0 , eay=0 ,ebx=0 ,eby=0;
for ( double i=-1;i<=1;i=i+0.000001)
{m=(0.5-i)*(0.5-i)+y*y;
eax=q*0.00005*(0.5-i)/pow(m,1.5)+eax;
eay=q*0.00005*y/pow(m,1.5)+eay;
n=i*i+y*y;
ebx=q*0.00005*(-i)/pow(n,1.5)+ebx;
eby=q*0.00005*y/pow(n,1.5)+eby;
}
m=eax*eax+eay*eay;
ea=pow(m,0.5);
m=ebx*ebx+eby*eby;
eb=pow(m,0.5);
cout<<"ea="<<ea<<endl<<"eb="<<eb<<endl<<"请输入高度"<<endl;
}
}
附件: 您所在的用户组无法下载或查看附件