Question

Must be done with recursion, no iterative solutions Newtons method for approximating square roots. The next...

Must be done with recursion, no iterative solutions

Newtons method for approximating square roots.

The next iteration is the average of the previous iteration and the ratio of the number in question to the previous iteration

.x_i = ( x_(i-1) + number/x_(i-1) ) / 2

if i is 0 the approximation is half the number.

Pre: number & interations are non-negative integers

Post: return an approximation of sqrt(number) , the return value is double

double newton(size_t number, size_t iterations){}

Homework Answers

Answer #1


#include<iostream>
#include<cmath>

using namespace std;

double root(double x, double e);

int main() {

double x,e;

cout<<"Enter a number : ";
cin>>x;
cout<<"Enter which root is to be found out ";
cin>>e;


cout << root(x,e);

return 0;
}


double root(double x, double e)

{
double a = x;
if (abs(a*a - x) <= e)
{
return a;
}
else
{
return root((a*a + x) /(2*a),e);
}

}

This is a recursive cpp code for finding square root of a number using newton's formula.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT