Question by Mutagen: java calculator.. how to solve division without using “/”?

Best answer:

Answer by JoelKatz
Probably the easiest way is to use Newton’s method.

Basically, use the following mechanism:

1) Pick a number that’s definitely too big to be the answer and a number that’s definitely too small to be the answer. Call these the ‘upper limit’ and ‘lower limit’. (You can use the largest and smallest numbers your calculator is designed to handle.)

2) Calculate the number halfway between the upper and lower limits. (You can use a binary shift to divide by two.)

3) If the lower and upper limits are close enough to each other, stop. The number we calculated in step 2 is the answer.

4) Do a trial multiplication to determine if the number we calculated is too small or too large to be the correct answer.

5) If the number is too small, replace the lower limit with the trial number. If the number is too large, replace the upper limit with the trial number.

6) Go to step 2.

What do you think? Answer below!

Tags: , , , , ,

Related Posts

Tagged with:

Filed under: NET Pay Calculator Answers

Like this post? Subscribe to my RSS feed and get loads more!