Tutorial 4
Tutorial 4
Tutorial N°4
Introduction to Algorithmics
Exercise 1
Execute the following algorithm, giving the final value of each variable:
Algorithm Exo1
Variables:
E : real
A, B, D : integers
Begin
A←2
B←3
D ← A*B+5
E ← D/2
End
Exercise 2
What are the errors in the following algorithm:
Algorithm ELSE
Variables :
E : real
A, B, C : integers
1m ← real
Begin
A←2
B←3
C ← (A+B)/2
1m ← C*B
End
Exercise 3
Write an algorithm that allows entering a number and displaying its double as well as its half.
Exercise 4
Write an algorithm that allows interchanging the values of two integer variables.
a) with the use of an intermediate variable,
b) without the use of an intermediate variable.
Exercise 5
Write an algorithm that allows arranging two integer numbers A and B in ascending order, then an algorithm
that arranges three integer numbers A, B, and C.
1
1st Year Preparatory Class - HNS of Renewable Energies, Environment & Sustainable Development Computer Science 1
Exercise 6
Write an algorithm that finds the maximum (max) and minimum (min) between two given numbers a and b
and then between three given numbers a, b, and c.
Exercise 7
Write an algorithm that explains the method of solving a second-degree equation in the set of real numbers.
Exercise 8
Write an algorithm that allows finding the minimum and maximum in an array of 10 integer elements.
Exercise 9
Write an algorithm that allows calculating the number of occurrences of a given number x in a ten two-
dimensional integer array.
Exercise 10
Using the principle of functions, write an algorithm that allows calculating:
𝑁
∑(𝑅 𝑖 + 1 / 𝑃𝑖+1 )
𝑖=1
Exercise 11
Write an algorithm that allows calculating the sum of the maximums of the rows of a two-dimensional array.
NB: Use a function that receives the line number as a parameter and returns the maximum in that line.