Joseph Miller <mailto:joseph.p.mil...@worldnet.att.net> said:

##### Quote

>If anyone knows TP, please write me a algorithm, and code to solve this

>problem:

>A program using a "divide-and-average" algorithm for approximating square

>roots. Accepting positive real values for variables: "Posreal", "Approx",

>and "Epsilon", and approximate the square root of "Posreal" by repeatedly

>replacing "Approx" by the average of "Approx" and "Posreal/Approx", until

>"Approx" and "Posreal/Approx" differ in value by less than "Epsilon", where

>value of "Epsilon" is small.

>I know it's simple, (like I can do the math), but this problem is driving me

>insane!

OK, you can do the math. What you need to do is approach the algorithm

in a practical way. You could do this using recursion but I would

suggest that a repeat..until loop would be best for your purposes.

You'll need to declare the variables using one of the relevant types

real/single/double/extended depending on the accuracy you are looking

for in your program. If you have been given a minimum value for

"Epsilon" then that will help determine which data type to use.

Your code is going to look something like {in pseudo code}:

input variables, checking they are in an allowed range

repeat

do the math

until posreal/approx < Epsilon

For general help, the following may be useful:

Think about how you are going to do this if you had only pen and

paper available to you.

[1] What would you need to do to accomplish this and in what order.

[2] Write these steps down in the correct order and think about them.

[3] How are you going to accomplish each of these steps ?

[4] For each step go back to [1] unless you cannot simplify further.

Also check, for each step you want to simplify, if you have already

written the code you need.

[5] When you reach here then you have pseudo-code of each step. Go to [6]

Note: each 'step' will be a procedure, function or statement.

[6] Code your program based on the pen and paper outline. Go to [7]

[7] Test program and note any bugs. Go to [8] for bugs or [10] if none.

[8] Eliminate bug. With postable code, newsgroup is likely to help. Go to [9]

[9] If program works fine then go to [10] else go to [7]

[10] Your program works as expected. Hand in.