algorithmic I Ch I : Basic concepts – 1) My first algorithm 2023/2024
1- Introduction :
• Computer science is the science of automatic information processing.
• The computer is a machine capable of automatically performing arithmetic and
logical operations from programs defining the sequence of these operations.
• Why the computer?
The following table represents a small comparison between the human being and the
computer.
{We see that the advantage of one constitutes the disadvantage of the other and vice versa.
From there the objectives of the algorithmic course is to bring the intelligence of the human
being to be able to solve problems towards the machine to have correct results, in a fast
way, whatever the size of the problem}
2. Steps for solving a problem :
To solve a given problem, the following steps must be followed:
Example
Algorithm Average ; Program Average ;
Variable x, y, Avg : real ; Var x, y, Avg : real ;
Begin Begin
Write(“Give me two values“); Write(‘Give me two values’);
Read(x, y) ; Read(x, y) ;
Avg(x+y)/2 ; Avg:=(x+y)/2 ;
Write (“The average is : “, Avg); Write(‘The average is : ‘, Avg) ;
End End.
3. Definitions :
3.1 Algorithm : is a sequence of ordered actions (operations or steps) which makes it possible
to solve a given problem, such as for example the steps of solving a quadratic equation.
3.2 Langage algorithmique : is a set of rules that allows us to write an algorithm correctly.
3.3 Programme : is a sequence of instructions written in a programming language, it is the
Page 1 sur 3
algorithmic I Ch I : Basic concepts – 1) My first algorithm 2023/2024
translation of the algorithm into a programming language.
Examples of programming languages: Pascal, Fortran, C, C++, Java, Python….
4. Example of an algorithm : Calculation of the average between two real numbers.
Manual processing Automatic processing
Algorithm Average ;
Person A: I want you to calculate the Variable x, y, Avg : real ;
average between two real numbers Begin
Person B: Give me two values Write(“Give me two values“);
Person A: 5 and 6. Read(x, y) ;
Person B (after a while): The average is: Avg(x+y)/2 ;
5.5 Write (“The average is : “, Avg);
End
Manual processing:
Person A: 1) poses the problem, 3) provides the data, 7) retrieves the result.
Person B: 2) requests the data, 4) retrieves the data, 5) calculates the result,
6) transmits the result.
Automatic processing:
1) Person A: poses the problem to Person C.
2) Person C: understands the problem, designs an algorithm, translates it into a program,
compiles it, tests it, and sends it to Person A.
3) Person A: copies the program to his computer, runs the program.
4) Computer: On declaration, memory space is reserved for the three variables: x, y, and Avg.
Screen 5) [Inst 1], Cmpt: asks Person A
for two real numbers. (Display of
6) Person A: reads the msg on the Give me two values a message on the screen).
screen
5 6
7) Person A: type two numbers on the
keyboard (which are displayed on the The average is : 5.5
screen).
11) Person A : See the result 10) [Inst 4], Cmpt : Displays the
displayed on the screen. result on the screen.
keybord
central unit
x y
A.L.U
9) [Inst 3], Cmpt : calculation of the 5 6
result by the ALU and store it in Avg. 8) [Inst 2], Cmpt : read the data
(store the given values in
Avg memory in x, y)
C.U 5.5
Processor C.M
Exercise: Given a circle of radius r. Write an algorithm that reads the value of r then calculates and
displays the area of the corresponding circle.
Page 2 sur 3
algorithmic I Ch I : Basic concepts – 1) My first algorithm 2023/2024
Solution :
(1) Problem specification
Data : The radius r (real) → Results : The area A (real)
General diagram of the solution :
(2) Problem analysis
A = 3.14 * r * r
(3) Writing the corresponding algorithm
Algorithm Circle_Area ;
Constant pi=3.1416;
Variable r, s: real ; /*r : radius, a: area*/
Begin
/*Data reading*/
Print(“Give me the radius“);
Read(r) ;
/*Result calculation*/
a pi * r * r; /* or : a pi * r ↑ 2; */
/*Result display*/
Print (“The area is : “, a);
End
Page 3 sur 3