-->

2007年10月5日 星期五

10-5-2007 Homework

Project 1 of Chap. 2.
The Babylonian algorithm to compute the square root of a number n is as follows:
1. Make a guess at the answer (you can pick n / 2 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 you repeat steps 2 and 3, the closer guess will become to the square root of n.
Write a program that inputs an integer for n, iterates through the Babylonian algorithm five times, and outputs the answer as a double to two decimal places. Your answer will be most accurate for small values of n.

Ans of Project 1 of Chap. 2. :

Project 3 of Chap. 2.
Write a program that reads in two integers typed on the keyboard and outputs their sum, difference, and product.

Ans of Project 3 of Chap. 2. :

3 COMMENT:

Yao Jen 提到...

You need to iterate through the Babylonian algorithm five times.

SHIYUH :

okay...thanks !
I'll check and finish it !

Yao Jen 提到...

great job!