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
Correct answer will be upvoted else downvoted. Computer science.    You are given an integer n. Check if n has an odd divisor, more noteworthy than one (does there exist such a number x (x>1) that n is separable by x and x is odd).    For instance, assuming n=6, there is x=3. Assuming n=4, such a number doesn't exist.    Input    The primary line contains one integer t (1≤t≤104) — the number of experiments. Then, at that point, t experiments follow.    Each experiment contains one integer n (2≤n≤1014).    If it's not too much trouble, note, that the input for some experiments will not squeeze into 32-cycle integer type, so you should use no less than 64-digit integer type in your programming language.    Output    For each experiment, output on a different line:    "Indeed" if n has an odd divisor, more noteworthy than one;    "NO" in any case.    You can output "YES" and "NO" regardless (for instance, the strings yEs, indeed, Yes and YES will be perceived as certain).
Write an algorithm that reads 10 integer numbers and calculates the average for numbers that are divisible by 5.
Start with a pile of n stones and successively split a pile into two smaller piles until each pile has only one Each time a split happens, multiply the number of stones in each of the two smaller piles. (For example, if a pile has 15 stones and you split it into a pile of 7 and another pile of 8 stones, multiply 7 and 8.)  The goal of this problem is to show that no matter how the  pile of n  stones are split, the sum of the products computed at each split is equal to n(n - 1)/2. Using strong mathematical induction, prove that no matter how the pile of n stones are split, the sum of the products computed at each split is equal to n(n - 1)/2.

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