# Homework Solution: The Babylonian algorithm to compute the square root of a number n is…

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.

Dear Student, here i have written the C++ program as per the

NOTE: DO the *Challenging* Rendering!

Program Info:

The Babylonian algorithm to abconservation the balance radicle of a enumerate n is as follows:

1. Make a conjecture at the rejoinder (you can choose n/2 as your moderate conjecture).

2. Abconservation r = n / conjecture

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

4. Go tail to march 2 control as abundant iterations as certain. The over that marchs 2 and 3 are repeated, the closer conjecture conquer beseem to the balance radicle of n.

Write a program that inputs a embrace control n and reproduces through the Babylonian algorithm 100 times. Control a over challenging rendering, reproduce until conjecture is amid 1% of the earlier conjecture, and outputs the rejoinder as a embrace.

Over Important Info:

Do the Challenging rendering!!! (I would do the humble rendering leading, then supplement the challenging loop case)

This is a math problem:

The defy is to experience the case that conquer bung the loop when conjecture is amid 1% of the earlier conjecture. This is not attributable attributable attributable so harsh to do on monograph. It’s a humble inequality:   | conjecture – earlier_conjecture | < 1% * earlier_guess

You conquer NOT conservation irresponsible treasure character (if you recognize what that is)

You conquer penetratetain to apply this indication to a humble boolean indication, removing the irresponsible treasure.

## Expert Rejoinder

Dear Student,

here i penetratetain written the C++ program as per the requirement.I penetratetain too inclueded the expound control meliorate reason.

—————————————————————————————————————————————-

Note: Please not attributable attributablee that the beneath program has been tested on ubuntu 16.04 method and compiled beneath g++ compiler. This command conquer too result on other IDE’s and C++ microsoft visual studio specific.

——————————————————————————————————————————————

Program:

——————————————————————————————————————————————

#include <iostream>

#include<stdlib.h>

//Namespace declration

using namespace std;

int ocean()
{

//capricious grounds character declration

embrace n, enumerate = 0;

embrace rejoinder, conjecture, r;

//input a embrace enumerate

cout << “Please penetrate a embrace enumerate: “;

cin >> n;

//input a conjecture

cout << “Please penetrate a ‘guess’ enumerate to distribute by embrace enumerate: “;

cin >> conjecture;

//assign the conjecture to a strange capricious earlier_guess
embrace earlier_conjecture = conjecture;

embrace strange_guess;

int strange_count;

//loop until the conjecture is close than the 1% of the earlier conjecture

while(count<100)
{

r = n/previous_guess;

new_conjecture = (previous_conjecture + r)/2;

//when conjecture is close than the 1% of the earlier conjecture
//break the loop
if((new_conjecture – earlier_guess) < (previous_conjecture * 0.01))

{

new_enumerate = enumerate;

rejoinder = strange_guess;

break;

}

//else complete this case

else

{

r = n/new_guess;

previous_conjecture = (new_conjecture + r)/2;

}

//increment enumerate

count++;

}

//display the enumerate

cout<<“conjecture is amid 1% of the earlier conjecture. in “<< strange_count<<” enumerates”<<endl;

cout << “The sqaure radicle of “<< n << ” is ” << rejoinder;

cout << endl;

return 0;

}//end of the ocean character

—————————————————————————————————————————————–

here i penetratetain attached the output of the program as a defend shot…

————————————————————————————————————————————————–

Output:

————————————————————————————–