You are on page 1of 3

University of Science and Technology Houari Boumediene

Faculty of computer science


Algorithmics and Data Structures INGENIEUR.INFO: 2023/2024

TD N° 1: Algorithmic Language

Exercise 1:

Propose an algorithm that takes a duration in seconds as input and converts it into hours,
minutes and seconds for display purposes.

Exercise 2:

Set the flowchart then the algorithm allowing to solve each of the following problems :
1- Solution in R of the first degree equation Ax+B=0 (A and B are real numbers).
2- The bill of a product depending on the sold quantity, knowing that the unit price depends
on the sold quantity as shown in the following table:

Quantity (Kg) Unit Price (DA)


Qte <10 10
10 <= Qte < 100 9
Qte ≥ 100 8

3- Determination of the Max of three integer numbers ( A , B , C ).


4- Ordering in decreasing order of three integers ( X , Y , Z ).
5- Solution of the second degree equation A x 2 + B x + C = 0 in the set of real numbers R.

Exercise 3:
Write an algorithm which computes the cost of a quantity of water consumed by a subscriber
knowing that SEAAL uses a rate per part as shown in the following table :

PART QUANTITY (M3) UNIT PRICE (DA)


1 25 6.30
2 30 20.48
3 27 34.65
4 The RESTE 40.95

Exercice 4:
Write an algorithm which displays the season according to the month number.

Exercice 5:
Write an algorithm which displays the type of medal obtained by an athlete (Gold, Silver,
Bronze) or no medal according to the position in the competition.
Exercice 6:
Write an algorithm to solve each of the following problems :
1- Calculation of the number of positive values, number of negative values, the sum of
negative values, the sum of positive values and the number of null values in a suite of N
integers.
2- Display of the number of upper case letters and lower case letters from a sequence of
characters ending by the character '#'.
3- Search for the minimum and the maximum of a set of de N real numbers.
4- Calculation of the quotient and the remainder of the division of two integers A and B
without using the division operation (we assume we don’t have operations Mod and Div).
5- Verification if a positive integer X is prime or not.
6- Calculation of the sum of the digits of a positive integer A.
7- Calculation of the occurrence number of the digit C (0 ≤ C < 10) inside a positive integer
A.
8- Calculation of the sum of the perfect numbers which are between 5 and N (A positive
integer A is perfect if it is equal to the sum of its divisors < A).

Exercise 7:
Write an algorithm which displays the Mirror of a positive integer A.
Example : Mirror of 26538 = 83562

Exercise 8:
Write an algorithm which determines the GCD (Greater Common Divisor) of two integer
numbers using the following methods:

Méthod 1 : successive substractions. Méthod 2 : euclidian division.


GCD ( 3465 , 1575 ) GCD ( 7038 , 5474 )

A B Reste A B Reste
3465 – 1575 = 1890 7038 / 5474 1564
1890 - 1575 = 315 5474 / 1564 782
1575 – 315 = 1260 1564 / 782 0
1260 – 315 = 945
945 – 315 = 630
630 – 315 = 315 3465 / 1575 315
315 – 315 = 0 1575 / 315 0

Exercise 9:
Write an algorithm which displays the Nth value of the suite (UN) knowing that :
U0 = 0 ; U1 = 1 ; U2 = 2 ; UN = UN-1 + UN-3 for N > 2.
Additional Exercises

Exercise 1 :
Let the three digits A, B and C (0 ≤ A, B, C ≤ 9). Write an algorithm which generates and
displays the largest and the smallest number which we can form by combining A, B and C.

Exercise 2 :
Using the instruction ”Case … Of”, write an algorithm which given the number of the month
displays the name of the month (eg. January is displayed when 1 is given).

Exercise 3 :
Write an algorithm to solve each of the following problems :
1- Calculation of the sum of the N first integers..
2- Calculation of the product of two integers using only the addition '+’ operation.
3- Calculation of the occurrence number of the character in a suite of N characters.
4- Determination if A is divisible by B with A and B positive integers.
5- Determination of all the divisors of a given integer X.
6- Calculation of the sum of the first K prime numbers.
7- Calculation of the factorial of a natural number N.
8- Calculation of AN using only the multiplication operator ( A integer and N natural number).

Exercise 4 :
Write an algorithm which displays multiplication tables from 1 to 9 for all values from 1 to 9.
1x1=1 2x1=2 … 9x1=9
1x2=2 2x2=4 … 9 x 2 = 18
. . … .
. . … .
1x9=9 2 x 9 = 18 … 9 x 9 = 81

Exercise 5 :
Write an algorithm which asks the user for a number between 1 and 3 until the answer is
correct.

Exercise 6 :
Write an algorithm which computes the order N sum of 𝑆𝑛 défined as follows using only the
basic operators (without using the power operator).
𝑁 𝑖+1
(−1)
𝑆𝑛 = ∑ 𝑖
𝑖=0 𝑥

Exercise 7 :
Write an algorithm which determines and displays the Nth value UN of ‘FIBONACCI’ suite

knowing that U1 = 1 ; U2 = 1 ; UN = UN-1 + UN-2 for N > 2.

You might also like