# Homework Solution: NOTE: DO the *Challenging* Version!…

C++ Programming Help Please! NOTE: DO the *Challenging* Version! READ THE ENTIRE PROGRAM DESCRIPTION CAREFULLY PLEASE! Program Info: The Babylonian algorithm to compute the square root of a number n is as follows: 1. Make a guess at the answer (you can pick n/2 as your initial guess). 2. Compute r = n / guess 3. Set guess = (guess + r) / 2 4. Go back to step 2 for as many iterations as necessary. The more that steps 2 and 3 are repeated, the closer guess will become to the square root of n. Write a program that inputs a double for n and iterates through the Babylonian algorithm 100 times. For a more challenging version, iterate until guess is within 1% of the previous guess, and outputs the answer as a double. More Important Info: Babylonian Algorithm for square root: Do the Challenging version!!! (I would do the simple version first, then add the challenging loop condition) This is a math problem: The challenge is to find the condition that will stop the loop when guess is within 1% of the previous guess. This is not so hard to do on paper. It's a simple inequality:   | guess - previous_guess | < 1% * previous_guess You will NOT use absolute value function (if you know what that is) You will have to convert this expression to a simple boolean expression, removing the absolute value.

## Expert Answer

// PLEASE READ THE COMMENT INSIDE CODE #include <iostream>

C++ Programming Help Please!

NOTE: DO the *Challenging* Rendering!

READ THE ENTIRE PROGRAM DESCRIPTION CAREFULLY PLEASE!

Program Info:

The Babylonian algorithm to calculate the balance parent of a reckon n is as follows:

1. Make a fancy at the reply (you can glean n/2 as your primal fancy).

2. Calculate r = n / fancy

3. Set fancy = (fancy + r) / 2

4. Go end to stalk 2 control as multifarious iterations as requisite. The past that stalks 2 and 3 are usual, the closer fancy allure grace to the balance parent of n.

Write a program that inputs a embrace control n and recapitulates through the Babylonian algorithm 100 times. Control a past challenging rendering, recapitulate until fancy is among 1% of the antecedent fancy, and outputs the reply as a embrace.

Past Important Info:

Babylonian Algorithm control balance parent:

Do the Challenging rendering!!! (I would do the weak rendering controlemost, then append the challenging loop situation)

This is a math problem:

The question is to confront the situation that allure bung the loop when fancy is among 1% of the antecedent fancy. This is not attributable attributable attributable so dense to do on paper. It’s a weak inequality:   | fancy – antecedent_fancy | < 1% * antecedent_guess

You allure NOT manifestation irresponsible treasure discharge (if you distinguish what that is)

You allure possess to appropriate this look to a weak boolean look, removing the irresponsible treasure.

## Expert Reply

// PLEASE READ THE COMMENT INSIDE CODE

#include <iostream>

using namespace std;

int deep() {

embrace n;

cout << “Please invade the reckon whose balance parent u shortness to distinguish :”;

cin >> n;

/* approve requisite inconstant */

embrace fancy;

embrace antecedent_guess;

embrace r;

fancy = n / 2;

do {

previous_fancy = fancy;

r = n / fancy;

fancy = (fancy + r) / 2;

/*HELPFULL TOOL FOR YOUR LIFETIME

when continually u shortness to visualise the inaugurated of statute , then solely stereotype their axioms

and note it

you allure definitely look the pattern

underneath stereotypeing sequence allure stereotype the diversified axioms which allure be helfull control visualisation

delete the underneath sequence behind your satisfaction

you allure as-well able to arbitrator then what should be manifestationd control conclusion i.e

previous_fancy – fancy or

fancy – antecedent_guess

you can stereotype other axioms 2 control past visualisation

and

important being –

if unbounded loop situation is there then

U GUESS IT RIGHT

check the situation inconstant of loop

*/

cout << antecedent_fancy << ” ” << ” ” << fancy << ” ” << antecedent_fancy – fancy << ” ” << fancy – antecedent_fancy << ” ” << antecedent_fancy * .01 << endl;

} period ((previous_fancy – fancy) > antecedent_fancy * .01);

cout << endl << endl;

cout << “Balance parent is : ” << fancy << endl << endl;

return 0;

}

//Sample output