Thursday, 10 January 2013

Program to Find the Square Root of a Number

  Finding the square root of a number is a very trivial operation in Mathematics. But how to find the square root of a number using some programming language like C or C++? Almost every programming language has a built in function to perform this operation. For example C and C++ has sqrt( ) defined in the header file math.h. But how to find the square root without using any standard library function? There are many different solutions available to this problem. Here I have posted programs to find the square root based on two different techniques. Babylonian Method (Heron's Method) and High/Low Method.

Babylonian Method (Heron's Method)
  
  This method is credited to the Babylonians and sometimes to Hero of Alexandria, a first-century Greek Mathematician. The technique is described below.

            To find the root of a number X, start with an initial approximation R0.
            R0X. 
          Rn+1=( Rn + ( X/Rn ) )/2.
            Repeat the process until you get a sufficiently accurate answer. 
High/Low Method
  
  This method is similar to the bisection method. This method involves guessing a approximate value for the square root of a number based on known squares. The guessed value is checked if it is too high or too low and adjusting accordingly until a sufficiently accurate answer is obtained.

Click Here to Download the C Program to find the Square Root of a number using Heron's Method. 
Click Here to Download the C++ Program to find the Square Root of a number using Heron's Method.

 

No comments:

Post a Comment