Babylonian algorithm

Assignment Help Data Structure & Algorithms
Reference no: EM13703792

Question: Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as given:

Step 1: Make a guess at the answer (you can pick n/2 as your initial guess).

Step 2: Computer = n / guess.

Step 3: Set guess = (guess +r) / 2.

Step 4: Go back to step 2 until the last two guess values are within 1% of each other.

Program: Write a program that inputs an integer 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. INPUT and PROMPTS. The program prints "This program estimates square roots." and then prompts for a positive integer as follows: ("Enter an integer to estimate the square root of: " and then reads in the integer . OUTPUT .

Each time a new guess is computed, the program prints it he line "Current guess: g", where g is the current guess, printed out with no special formatting. The final output is "The estimated square root of x is y", where x is the integer that was read in and y is the value computed by the procedure described above, printed out to two decimal places and a total of six characters . CLASS NAMES. Your program class should be called Babylonia

The solution must be error free and compile correctly on first attempt.  Any code that does not do this will not be awarded points.

Reference no: EM13703792

Questions Cloud

Write a function named totamt : Write a function named totamt() that uses four parameters named quarters, dimes, nickels, and pennies, which represent the number of each of these coins in a piggybank.
Redesign the grading program as an object-oriented design : Redesign the grading program as an object-oriented design. We will start with a simple Student class. The student will have a name, an id (as a String) and a set of grades (as doubles).
What is the output of the statement : Given the subsequent array declaration, if the array is stored starting at address 2500, what is the output of the following statement?
Can firm increase variability of its product line : Can a firm increase the variability and diversity of its product line while simultaneous realizing the higher possible level of efficiency? Provide one product example for illustration.
Babylonian algorithm : Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as given:
Write a program that request a students name : Write a program that request a student's name in the subsequent form: lastName,firstName.
Determining the volume of the unit sphere : Write a C program for determining the volume of the unit sphere by the Monte Carlo Method      \(x^{2}+ y^{2} + z^{2} 0, y > 0, z > 0.\)    : This is what I have so far, but it's not working.
How will cyber security influence the next 10 years : How will cyber security influence the next 10 years?
Prepare a main function : Write a function that converts an input of some integer number of nickels into outputs of integer numbers of dollars, quarters, and nickels.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  In addition make a flow-chart to show how to sort using one

there are many additional algorithms available. choose 2 sorting and 2 searching algorithms and describe them in

  Describe and analyze an algorithm

Describe and analyze an algorithm to determine, given the initial sequence of cards, the maximum number of points that you can collect playing against a perfect opponent.

  Binary search tree adt

Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value.

  Illustrate insertion into the linear hash file

Illustrate insertion into the linear hash file. Suppose that bucket splitting occurs whenever file load factor exceeds (is greater than) 0.8.

  Program to create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  Define file type

Define File Type and provide some of the important information to know about it and where do file types come from?

  Calculate the total weights and values of each subset

Use the decrease-by-one technique to generate the power set and calculate the total weights and values of each subset, then find the largest value that fits into the knapsack and output that value.

  Computing minimal length of key-average cracking time given

If Encrypt-It-Rite would like to increase average cracking time to at least 100 years, determine the minimal length of the key?

  Implement a nice graph datastructure

Implement a nice graph datastructure. Implement two different greedy graph coloring algorithms. Shortest path algorithm and MST algorithms.

  Create all the possible combinations of array a

The subset-sum problem is defined as follows: given a set B of n positive integers and an integer K, can you find a subset of B whose elements' summation is equal to K? Design an algorithm to solve this problem. Address its correctness and running..

  Equation apply boolean algebra

Using this equation apply boolean algebra in order to prove the commutative and associative properties for binary addition: x(+)y=y(+)x  (x(+)y)(+)z=x(+)(y(+)z)

  Create a binary search tree program

Creating a Binary Search Tree program - Finding the largest and smallest values in the tree Add two class methods

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd