Task #2
Question#1:
Write a recursion function named GCD that computes the greatest common divisor of two integers.
Based on the observation that, if r is the remainder when a is divided by b, then the common divisors of
a and b are the same as the common divisors of b and r. Thus we can use the equation: GCD (a, b) =
GCD (b, r) .
For example, GCD (36, 20) = GCD (20, 16) = GCD (16, 4) = GCD (4, 0) = 4 implies that the GCD of
36 and 20 is 4. It can be shown that for any two starting numbers, this repeated reduction eventually
produces a pair where the second number is 0. Then the GCD is the other number in the pair.
Question#2:
(Guess the Number Game) Write a program that plays the game of "guess the number" as follows: Your
program chooses the number to be guessed by selecting an integer at random in the range 1 to 10. The
program then displays the following:
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program responds with one of the following:
1.
2.
3.
Excellent! You guessed the number!
Would you like to play again (y or n)?
Too low. Try again.
Too high. Try again.
Question#3 (Bonus):
Write A recursive function to determine if an input is prime number or not.