#WSQ10

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);
}

Advertisements

2 comments on “#WSQ10

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s