You are on page 1of 2

Christmas Challenge

1. Write a program that asks for a number and returns whether the number is positive,
negative or zero.

2. Write a program that asks for 5 numbers and calculates (and returns) their sum and
average.

3. Modify the above program to calculate sum and average for positive numbers only.

4. Write a program to calculate (and print) the electricity bill of a given customer. The
units consumed will be given by the user. The charges apply as follows:

up to 199 - 0.32euros/each
200 and above but less than 500 - 0.45euros/each
above 500 - 0,58euros/each

Please note that proportional charges apply meaning that if someone has consumed
250 units, they will be charges with 0,32/each for the first 199 and with 0,45/each
for the rest.

If the bill exceeds 100euros, and extra fee of 30 euros applies.

5. Write a program that asks for 2 numbers and calculates (and returns) the largest.

6. Write a program that asks for 3 numbers and calculates (and returns) the minimum.

7. Write a program that asks for 4 numbers and calculates (and returns) the maximum.

8. Write a program that asks for 5 numbers and calculates (and returns) the maximum
and the minimum.
Hint: this does not need many code lines to be written, you just need to come up
with a formula -this is why it goes gradually from exercise 3 to here.

9. If you have the formula try the following.


Write a program that asks for 20 numbers and calculates (and returns) the maximum
and the minimum.
Students who were not here last week (Alex, George, Melina) will find that -and the
following exercises- hard. Please read the loops from your book and give it a try. Just
a try :)

10. Write a program that adds all numbers from 1 to 1000.

11. Modify the previous program to also calculate the average.


12. Write a program that asks the user for a number n and calculates and prints the sum
of the numbers from 1 to n.

13. Modify the above program to also calculate the average, the maximum and the
minimum.

14. Write a program that calculates the sum of the positive numbers the user provides.
Hint 1: we do not know how many numbers the user will give.
Hint 2: the program has to stop when the user gives a non-positive number.

15. Modify the above program to also calculate the average of the given numbers.

16. Write a program that asks from the user to give numbers.
If the given number is positive we need to calculate sum and average.
If the given number is negative we need you calculate the product.

17. Write a program to calculate the factorial of a given number.

You might also like