Tutorial Algorithm
Tutorial Algorithm
Exercise 1:
Write an algorithm that reads 2 numbers and determines the largest and smallest
Exercise 2: Write an algorithm that reads two integers and displays the quotient
and the rest of the Euclidean division of these two numbers.
Exercise 3:
Write an algorithm that requires the input of any letter of the alphabet. If the letter
entered corresponds to the initial of the day of the week, there is the following
display:
"The letter L corresponds to Monday" if the letter entered is L for example.
"The letter M corresponds to Tuesday or Wednesday" if the letter entered is M for
example.
Otherwise show
"The letter A does not correspond to any day of the week" if it is the case of the
letter A.
1 Algorithm computation;
2 x, y, z: integer;
3 begin
4 x:=5;
5 y:=10;
6 z:=2*x-y;
7 z:=y-6;
8 y:=x+z+6;
9 x:=6*y;
10. write(x)
11. y:=y-1;
12 write (y,z);
13 end
a) perform the manual execution of this algorithm;
b) deduce the values of x, y, and z displayed.
Exercise 5:
Write an algorithm to swap 2 integer objects using an intermediate variable.
Exercise 6:
Write an algorithm that asks you to enter a word from the keyboard, and then
displays the word entered, its frst and last letter, and its length.
Exercise 7:
Write an algorithm which reads 10 integer numbers, calculate their sum and
displays the result.
Exercise 8:
Write an algorithm that reads 12 real numbers and calculates the mean, variance,
standard deviation and then displays them.
Exercise 9:
Write an algorithm that reads a positive integer and calculates the factorial of that
number. The algorithm must accept only positive or zero numbers and ignore all
negative numbers.
Exercise 10:
Write an algorithm asking to enter a word of any length and determining whether
the word is a palindrome or not. (e.g. redivider, deifed, civic, radar, level, rotor,
kayak, reviver, racecar, redder, madam, and refer)
Exercise 11:
Write an algorithm that calculates the sum and the average of the n frst natural
integers, then displays the results.
Exercise 12:
Write an algorithm which allows to reads 2 positives integers and calculates their
product using the following principle.
AxB=A+A+A+...+A, (B times).
Exercise 13:
Write an algorithm that reads an integer n and determines whether it is a prime
number or not. Principle: if any number less than n and diferent from 1 is not
divisor of n, then n is prime.
Exercise 14:
Write the algorithm that asks to enter a square matrix of order n, displays it,
calculates its trace and displays it. The algorithm then searches for the smallest
element of the matrix, the poster and its various coordinates.
Exercise 15:
Write an algorithm that reads an integer and displays its equivalent in binary
Exercise 16:
Write an algorithm that reads an integer n, calculates the elements of the pascal
triangle of depth n and fnally displays the triangle thus obtained.
Exercise 23:
Write an algorithm that reads 2 square matrices of order n, posters, calculates their
product and displays.