Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Lab 01: Recap 1 – Conditions and Loops

EXERCISE 1
Write a program that calculates the BMI of a person.
Formula : bmi=weight /height2 such as the weight is in Kg and the height is in m.

If BMI < 18 the the program displays under weight.


If BMI between 18 and 25 the program displays normal.
Between 25 and 30 the program displays over weight.
Greater than 30 the program displays obese.

EXERCISE 2
Calculate the price of a certain number of photocopies by applying the following tariff : the first
10 cost 1 euro/piece, the next 20 cost 0.5 euro/piece et all the others cost 0.25 euro/piece (save
the invariable numbers in constants)

EXERCISE 3
We want to pack N eggs in NB boxes of 12 eggs each. Determine, without using any division,
the number NB of boxes (completely filled, to be sealed), as well as the remaining number of
free eggs (the division will be simulated by successive subtractions).

EXERCISE 4
Write an algorithm that allows the clients of a restaurant to make an order. The program must
display the following menu :

1-Fish and Chips 10$


2-Hamburger 8$
3-ChickenBurger 8$
4-Dessert of the day 6$

The dialoge is as follows :

Enter the number of your meal of choice :...


Would you like to add anything else ? Type 1 for YES and 0 for NO.
The total of your bill is :

The menu will appear as long as the customer wants to add a dish. When the customer finishes
his order the program must display the amount of his invoice.

EXERCISE 5
Write a program that calculates the following sums. The integer is entered by the user.
S1 = 1 + 2 + 3 + ... + N
S2 = 1^1+ 2^2+ 3^3+ ... + N^n
P = 1 * 2 * 3 * ... * N

EXERCISE 6
Write a program that asks the user to enter 20 numbers then displays the maximum and
minimum.
EXERCISE 7
Read a series of 30 grades between 0 and 20, then display the lowest, the greatest,
the number of grades <10, and the number of grades >=10

EXERCISE 8
Write a program that displays the following triangle for N=5 (N is entered by the user):
1
12
123
1234
12345

EXERCISE 9
Write a program that displays the following square for N=5 (N is entered by the user) :
OXOXO
OXOXO
OXOXO
OXOXO
OXOXO

You might also like