Homework 5
Homework 5
Badour Albahar
Homework #5
November 10, 2024
Due Sunday, November 17, 2024 at 11:59PM in Moodle
Collaborators: (LIST OF YOUR COLLABORATORS, OR WRITE NONE)
1. Write a program that computes the Greatest Common Divisor (GCD) of two integers.
The program should use a recursive function call to calculate the GCD based on the following
formal definition:
x if y = 0
GCD(x, y) =
GCD(y, mod(x, y)) if x ≥ y and y > 0
where mod is the modulus function. The program asks the user to enter two integers. Then,
the program calls the GCD function and prints the result returned by the function.
Sample Output 1:
Sample Output 2:
Sample Output 3:
2. Write a program of Snake and Ladder game (picture shown below). Assume that there
are only two players Red and Green. Game starts with position one for both players. Use a
random number generator to roll a die of 6 faces 1, 2, 3, 4, 5, 6 in two functions: MoveRed()
and MoveGreen(). The die specifies the number of moves for a player, and its value should be
used to update two class-level variables: RedCounter and GreenCounter. Assume that Red
is playing first. Each time the player moves, check if the player reaches a snake or a ladder
and do the action. The winner of the game is the player who reaches 25 or more first.
Three Snakes:
Three Ladders:
Sample Output 1:
Game Started
Red and Green at Position one
Sample Output 2:
Game Started
Red and Green at Position one