Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 2, Problem 9PP

(This is an extension of an exercise from Chapter 1.) The Babylonian algorithm to compute the square root of a positive number n is as follows: n / 2

  1. Make a guess at the answer (you can pick 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 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, iterates through the Babylonian algorithm until the guess is within 1 % of the previous guess, and outputs the answer as a double to two decimal places. Your answer should be accurate even for large values of n.

Blurred answer
Students have asked these similar questions
Write this using java  Write a complete version of the Bresenham Midpoint algorithm to handle ALL slope values. m = 0 m > 0  m < 0 m = 1 m  > 1 swap the rolls of x and y m < 1 m = infinity ( needs special test case) Include appropriate tests for ‘special case’ conditions. Insteadof “WritePixel” write to the screen the coordinates of the pixel that would be drawn.
Start with any positive number n. If n is even divide it by 2, if n is odd multiply by 3 and add 1. Repeat until n becomes 1. The sequence that is generated is called a bumpy sequence. For example, the bumpy sequence that starts at n = 10 is: 10, 5, 16, 8, 4, 2, 1and the one that starts at 11 is11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 Write a function named lengthBumpy that returns the length of the bumpy sequence generated by its integer argument. The signature of the function is    int lengthBumpy(int n) Examples:lengthBumpy(10) returns 7, and lengthBumpy(11) returns 15. You may assume that the argument n is positive and that the sequence converges to 1 without arithmetic overflow.
What is the time complexity of the following snippet? (Complete steps should be shown)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY