Mesopotamia

In this WSQ, we had to find the square root of a number using the Babylonian method.

Here is a video that explains what’s going on, and here is another video showing how another student programmed this.

Once I had this information I could start programming.

#include <iostream>
using namespace std;

long double square(long double X)
{
  long double y=1, c;
  for(int i=0; i<1000; i++)
  {
    c=X/y;
    y=(y+c)/2;
  }
  return y;
}

int main()
{
  int X;
  cout << "Square Root... \n\nNumber: ";
  cin >> N;
  cout << "The square root of "<< N << " is equal to "<<square(X) << endl << endl;
  return 0;
}

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 )

Connecting to %s