C++ Programming Help Please!
NOTE: DO the *Challenging* Rendering!
READ THE ENTIRE PROGRAM DESCRIPTION CAREFULLY PLEASE!
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:
Babylonian Algorithm control balance radicle:
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.
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.
//Header improve declration
using namespace std;
//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;
//loop until the conjecture is close than the 1% of the earlier conjecture
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;
//else complete this case
r = n/new_guess;
previous_conjecture = (new_conjecture + r)/2;
//display the enumerate
cout<<“conjecture is amid 1% of the earlier conjecture. in “<< strange_count<<” enumerates”<<endl;
//display the squre radicle
cout << “The sqaure radicle of “<< n << ” is ” << rejoinder;
cout << endl;
}//end of the ocean character
here i penetratetain attached the output of the program as a defend shot…