Hi guys! It’s me again with a video of how to get the square root of a number using the old Babylonian method. The code and the link to the video are bellow:
#include <iostream>
#include <cmath>
using namespace std;
float babylonian_square(float x)
{
float ans, a=0;
ans=x/2;
do {
cout<<ans<<endl;
a=ans;
ans=(ans+x/ans)/2;
} while(abs (a-ans)>0.0001);
}
int main()
{
cout<<babylonian_square(2);
}
Nice!
LikeLike
[…] is a video that explains what’s going on, and here is another video showing how another student programmed […]
LikeLike