You are on page 1of 2

# Course «C Programming Language»

Topic: Recursion

Homework

Exercise 1.
Write a recursive function for finding the greatest common divisor of two integers.

Exercise 2.
Write a game called "Bulls and cows". The program "thinks of four-digit number"
and the player has to guess it. When the user has entered a number, the program
tells you how many numbers were guessed (bulls) and how many numbers were
guessed and they are on the right place (cows). After guessing a number, you
should output to the screen a number of attempts made by user. In a program you
should use recursion.

Exercise 3.
Chessboard 8x8 and chess knight are given. The program should request the
coordinates of cell from the user and put the knight there. The main purpose of the
program is to find and to output a path of the chess knight, according to which it
will go through all cells of the chessboard so that it will be in each cell only once.
(Since the process of finding a way for different primary cells may be delayed, it is
recommended first to try out this problem on the chessboard of 6x6). In a program
you should use recursion.

Exercise 4.
Write a recursive function to find a power of number.

Exercise 5.
Write a recursive function that outputs N stars in a row, the user specifies a number
N. Illustrate the work of function by example.

Exercise 6.
Write a recursive function that calculates the sum of all numbers in a range from a
to b. The user inputs a and b. Illustrate the work of function by example.

Exercise 7.
Write a recursive function that takes one-dimensional array of 100 integers filled
randomly and finds a position, from which a sequence of 10 numbers begins, the
sum of these 10 numbers is minimal.

1
Course «C Programming Language»

Topic: Pointers

Homework

Exercise 1.
Using two pointers to an array of integers, copy one array to another. Use in a
program the pointer arithmetic to move through the array, and the dereference
operator.

Exercise 2.
Change an order of elements in the array to opposite, using a pointer to an array of
integers.
Use in a program the pointer arithmetic to move through the array, and the
dereference operator.

Exercise 3.
Using two pointers to arrays of integers, copy one array to another so that the
elements of the second array will be arranged in a reverse order.
Use in a program the pointer arithmetic to move through the array, and the
dereference operator.

Exercise 4.
Determine the larger of two numbers using pointers and dereference operator.

Exercise 5.
Determine the sign of number entered from the keyboard using pointers and
dereference operator.

Exercise 6.
Exchange places of values of two variables using pointers and dereference
operator.

Exercise 7:
Write a primitive calculator, using only pointers.

Exercise 8:
Using a pointer to an array of integers, calculate the sum of elements of the array.
Use in a program the pointer arithmetic to move through the array, and the
dereference operator.
2