0% found this document useful (0 votes)
2 views6 pages

Algorithm Exercises for IRT License 2

The document contains a series of algorithm exercises aimed at teaching reading and writing operations, iterative structures, conditional control structures, and tables. It includes tasks such as calculating net salary, generating multiplication tables, finding the largest number from user input, and solving quadratic equations. Additionally, it covers topics like perfect numbers, sorting arrays, and determining the state of water based on temperature.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Algorithm Exercises for IRT License 2

The document contains a series of algorithm exercises aimed at teaching reading and writing operations, iterative structures, conditional control structures, and tables. It includes tasks such as calculating net salary, generating multiplication tables, finding the largest number from user input, and solving quadratic equations. Additionally, it covers topics like perfect numbers, sorting arrays, and determining the state of water based on temperature.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Algorithmic

License 2 - IRT
2020-2021
I- Exercises on reading and writing operations

Exercise 1:

Write the algorithm to calculate and display the net salary of an employee. Knowing that:

Net salary (NS) = Gross salary - Tax value


Gross salary (GS) = (Base salary (BS) + Child bonus) * Work rate
Taux de travail (TT) = Nombre de jours travaillés (NJ) / 26
Prime des enfants (PE) = Prime d’un enfant(P1E) * Nombre d’enfants (NE) Valeur de l’Impôt
(VI) = Tax Rate (TI) * Gross Salary

Exercise 2:

We are looking to write an algorithm that displays the multiplication table of a number n.
any. Example: n = 9
1*9=9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81

II- Exercise on iterative structures (For and While....


Do and Do... As long as
Exercise 1:

Write an algorithm that asks for a starting number, and then displays the ten numbers.
following. For example, if the user enters the number 17, the program will display the numbers from
18 to 27.

Exercise 2:

We want to write an algorithm that calculates the sum of positive integers less than or equal to N.

1
Algorithmic
License 2 - IRT
2020-2021

Exercise 3:

Write an algorithm that successively asks the user for 10 numbers and then tells them
then which was the largest among these 10 numbers:
Enter number 1: 7
Enter number two: 24
.......etc.
Entrez le nombre numéro 10 : 13
The greatest of these numbers is: 24

Exercise 4:

Ecrire un algorithme qui demande un nombre de départ, et qui calcule sa factorielle. NB : la


The factorial of 8, denoted 8!, is equal to 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8

Exercise 5:

Write an algorithm that asks for 10 integers, counts the number of positive integers entered, and
display this result.

Exercise 6:

Write an algorithm to create a chessboard of 8 by 8. We will represent the black squares


by 'x' and the white squares by spaces (figure 1).

X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X

Exercise 7:

The population of Alpha city is 1,000,000 residents and it is increasing by 50,000 residents.
per year. The city of Beta has a population of 500,000 inhabitants and it increases by 4% per year. Write a
algorithm to determine in how many years the population of the city Beta
will surpass that of the Alpha city.

Exercise 8:

Write an algorithm that asks the user for a number:


• Display the divisors of this number.

2
Algorithmic
License 2 - IRT
2020-2021
• The number of these divisors.
• The sum of the divisors of this number.

Exercise 9:

Write an algorithm to display the first terms of the following sequences (number of terms (n)
asked the user:
Arithmetic sequence: Un+1 = Un+ 2, U0 = 1

III- Exercise on conditional control structures


Exercise 1:

Write an algorithm that asks the user for the water temperature and displays its state (solid,
liquid, vapor.

Exercise 2:

Let's write an algorithm that specifies whether a triangle ABC is right-angled (and if so, at which point).
or if it is not.
Note: According to the converse of the Pythagorean theorem, if AB 2= AC 2+ BC,2then the triangle
ABC is a rectangle at C.

Exercise 3:

Write an algorithm and then a flowchart to find and display the smallest one.
value among three distinct real numbers A, B, and C.

Exercise 4:

Write an algorithm that asks the user for a real number and displays its absolute value (without using
of predefined function obviously).

Exercise 5:

Write an algorithm that asks the user to enter the grade and displays the mention as follows:

Weak; if score <= 10


Passable; if 10<=grade<=12
Fairly Good; if 12<=grade<=14
Good; if 14 <= grade <= 16
Good; if 16 <= grade <= 18
Excellent; if 18 <= grade <= 20

3
Algorithmics
License 2- IRT
2020-2021

Exercise 6:

Write an algorithm to solve a quadratic equation.

Exercise 7:

Write an algorithm to:


Read a finite number of notes between 0 and 10
Display the best score, the worst score, and the average of all scores.

Exercise 8:

Perfect numbers A perfect number is a number that is equal to the


sum of all its divisors, except for itself. The first perfect number is 6 = 3 + 2 + 1. Write
an algorithm that displays all the perfect numbers less than 500.

IV- Exercise on tables


Exercise 1:

Write an algorithm that declares and fills an array of 7 real numeric values.
setting everything to zero.

Exercice 2:

Write a procedure that searches for the index of a value in an array V of dimension N.
component containing the value X. First consider the case where we are sure that X is in
the vector, then the general case.

Exercise 3:

What does the following algorithm produce?


Square Something
Start
Array Nb(5) in Integer
Variable i in Integer For i = 0, 5
Nb(i) ← i * i
End For
For i = 0, 5 Write Nb(i) End For
End
Can we simplify this algorithm while getting the same result?

Exercise 4:

4
Algorithmics
License 2- IRT
2020-2021
Write an algorithm that allows the user to enter the grades of a class. The program,
Once the input is completed, return the number of these grades that are above the class average.

Exercise 5:
What do the following algorithms do?

a)
Var i, n (10) integer
Debut
n [0] ← 1
For i going from 1 to 9 Do
N(i) ← n (i-1) + 2
End
b)

Var i, n [10] integer


Start
For i going from 0 to 9 Do
N(i) ← 2 * i
End

Exercise 6:

Write an algorithm to solve the following problem:


Data: a table containing 100 integers
– Résultat : “vrai” si le tableau est trié du plus petit au plus grand et “faux” sinon

Exercise 7:

Write an algorithm to input 100 values and sort them as they are entered.
table

Exercise 8:

Ecrire un algorithme qui calcule le plus grand écart dans un tableau d’entiers. Rappel : l’écart
The absolute value of the difference between two integers x and y is |x − y|.

5
Algorithmic
License 2 - IRT
2020-2021

You might also like