求平方根的巴比伦算法
#include<iostream>
using namespace std;
double guess(int n)
{
double guess=static_cast<double>(n)/2;
int i=0;
while(i<10)
{
double r=n/guess;
guess=(guess+r)/2;
++i;
}
return guess;
}
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<guess(3)<<endl;
system("pause");
}