Exam 1 Practice Problems

If you would like to practice writing more C programs before the first exam, below are some problems you can try. Don’t forget that the exercises are also good practice.

Practice 1:

Write a function with three parameters:

Return the number of times the target integer appears in the array.


Practice 2:

Write a function with two parameters:

The function should replace every even element of the array with 1 and every odd element with 0. For example, the array {10, 3, 7, 4, 5} should become {1, 0, 0, 1, 0}.


Practice 3:

Write a function to print a triangle of asterisks, with the size of the triangle as a parameter. In main() use a loop to print several triangles of increasing size using your function, like so:

*

*
**

*
**
***

*
**
***
****

Practice 4:

Fizz buzz is a game where players count up starting with 1. Each time the next number is a multiple of 3, the next player must say “fizz” instead of the number. If the next number is a multiple of 5, the next player must say “buzz”. If the next number is a multiple of both 3 and 5, the next player must say “fizz buzz”. Here is a game of fizz buzz up to 16:

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizz buzz
16

Write a program which plays a game of fizz buzz up to a number specified by the user.