//用迭代法求近似平方根,考試大和你一起學(xué)習(xí):
#include
#include
using namespace std;
int main()
{
int flag = 0;
cout<<"please enter a number:";
double a = 0.0;
cin>>a;
const double EPSTLON = 1E-14;
double xnew = a;
double xold = 0.0;
do{
xold = xnew;
xnew = (xold + a/xold)/2;
}while(fabs(xnew - xold) > EPSTLON);
cout<<"the square root is:"< cin>>flag;
return 0;
}
#include
#include
using namespace std;
int main()
{
int flag = 0;
cout<<"please enter a number:";
double a = 0.0;
cin>>a;
const double EPSTLON = 1E-14;
double xnew = a;
double xold = 0.0;
do{
xold = xnew;
xnew = (xold + a/xold)/2;
}while(fabs(xnew - xold) > EPSTLON);
cout<<"the square root is:"<
return 0;
}