Sunday, November 05, 2006

 

Turing, Ch 6 - hints for a few questions

The questions below are challenging questions for the stronger programming students. If you can't figure them out, don't worry. You can safely ignore them.

QUESTION #9 (p. 114) asks you to find the sum of a number of terms of the series of numbers 1 + x + x**2 + x**3 + x**4 .. . This is a challenging question for the stronger students in the class.
HINTS:
- The tricky part in this question is in how you set up the counter (index) for your counted loop.
- You need to recall a little math - What's the value of x0 and x1?

QUESTION #13 (p. 115) asks you to find all the factors of an integer.
HINTS:
- Try all integers from 1 to the number.
- For each one, how do you decide whether it is a factor? Well, a factor of a number divides into the number evenly. That's the definition of a factor.
- Hint: Have a look at a very useful operator called div (p. 101).

QUESTION #14 (p. 115) asks you to take an integer from the user and output the number of digits in it. This is a challenging question for the stronger students in the class.
HINTS:
- Tell the user to enter an integer of 6 digits or less. The book doesn't mention this, but obviously there's a problem if the user can enter ANY number, no matter how large.
- Use div and multiples of 10 as a divisor.

QUESTION #16 (p. 115) asks you to generate random real numbers between, 4 and 5, 0 and 10, and so on. Be sure you learn how to do this. (It's not hard once you think about it, knowing what rand(number) does.)



<< Home

This page is powered by Blogger. Isn't yours?