Posts

Showing posts with the label square root using recursive function

Square Root using Recursive Function

/*  * SquareRoot.cpp  *  *  Created on: Dec 2, 2010  *      Program Description:  *      This program would calculate the square root of a number entered by user using  *      recursive function as well as the non recursive version of it.  */ #include<iomanip> #include<cmath> #include<iostream> using namespace std; const double tol = 1.0E-4; // Tolerance constant. // Function Prototypes double sqrRootRecursive(double, double, double); double sqrRootNonRecursive(double, double, double); // Function Definitions double sqrRootRecursive(double number, double approx, const double tol) { // Using Recursive function to calculate Square Root of user input. if (fabs (approx * approx - number) <= tol) return approx; else if (fabs((approx * approx) - number) > tol) approx = sqrRootRecursive(number, (approx * approx + number) / (2 * approx), tol); return...