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
The greatest common divisor of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid’s algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: Compute the remainder of dividing the larger number by the smaller number. Replace the larger number with the smaller number and the smaller number with the remainder. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5
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).
A formula for finding the greatest common divisor (GCD) of two numbers was formulated by the mathematician Euclid around 300 BCE. The GCD of two numbers is the largest number that will divide into both numbers without any remainder. For example, the GCD of 12 and 16 is 4, the GCD of 18 and 12 is 6.The basic algorithm is as follows:Assume we are computing the GCD of two integers x and y. Follow the steps below:1. Replace the larger of x and y with the remainder after (integer) dividing the larger number by the smaller one.2. If x or y is zero, stop. The answer is the nonzero value.3 If neither x nor y is zero, go back to step 1.Here is an example listing the successive values of x and y:   x          y135         20       %(135 / 20) = 15 15         20       %(20 / 15) = 5 15          5       %(15 / 5) = 0      0          5       GCD = 5       Write a recursive method that finds the GCD of two numbers using Euclid’s algorithm. public class Arithmetic{   public static int gcd(int a, int…

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