Sunteți pe pagina 1din 1

Exercises

Please try these at home and be ready next Tuesday. I will randomly pick people and ask them to do
these on the board.

1. Write an algorithm to calculate the factorial of any given number.

2. Write an algorithm for a guessing game where the user has to guess a secret number. After
every guess the program tells the user whether his number was too large or too small. At the
end, the number of tries needed to guess the number should be printed.

3. Write an algorithm to find the arithmetic average of a long list of positive numbers. The final
number in the list is a zero and this number is not repeated anywhere else in the list.

4. Write an algorithm to calculate ∑5𝑖=1 ∑100 ∑ 𝑘


𝑘=1 𝑗=1 (𝑗𝑘) 𝑖

5. You are given 1000 integers. Write an algorithm to find the maximum of those 1000 numbers,
and how many times this maximum number is repeated in the set of 1000 integers (that is, for
an example, if the maximum is 10, how many 10's are there among the 1000 integers).

S-ar putea să vă placă și