algorithmic I Ch I : Basic concepts – 2) Variables and constants 2023/2024
5. The algorithmic language :
It is a language very close to natural language and independent of the chosen
programming language.
An algorithm is as follows:
Algorithm name of algorithm ;
Declarative part;
Begin
Actions part ;
End.
The objects: (constants, variables) that an algorithm manipulates must be defined (or
declared) before their use.
Any instruction (action) is followed by a “; “ to separate it from another action.
Comments can be located anywhere in the algorithm, they are used by the programmer to
clarify the algorithm and not by the machine.
A comment is enclosed in /* */.
5.1 Concept of declaration:
Syntaxe :
Variable identifier: type ;
Constante identifier = value ;
Constante : is an object with a value that cannot be modified.
Example : Constant Pi = 3.141559
Variable: is an object whose value can be modified at any time.
She may be :
- an input data;
- a final result of a calculation;
- an intermediate calculation result. (Auxiliary variable)
Example: Variable x, y: integer; z: real;
5.1.a) Identifier: is the name of a variable, constant, algorithm or sub-algorithm. An
identifier begins with an alphabetical letter, followed or not by alphabetic letters, numbers, or
"_".
Example: Ali, name, x1, avg, Avg_1 are valid identifiers.
#B, A.X, 1B2, x 1 are incorrect identifiers.
5.1.b) Types of Values :
Constant identifier = value ;
We have 5 basic values :
Integer : set of integer numbers like : 2, -5, 0, ....
Real : set of real numbers like :2.4, -5, 0, -0.3 ....
Boolean : two values only are possible : true, false
Character : any number, or letter or symbol in one position putted in ‘’ is considered as
character value. Example : ‘a’, ‘4’, ‘)’, ‘#’, ‘+’, ‘ ‘, ....
String : is a set of characters putted between “”. Example : “good morning”, “g4+]@, “ “,
“”, ....
5.1.c) Basic types :
Variable identifier : type ;
Page 1 sur 2
algorithmic I Ch I : Basic concepts – 2) Variables and constants 2023/2024
1) Integer type : This data type is used to store whole numbers. i.e. values with no decimal
places. It can be positive, negative or null.
Example of an integer variable : age, number_of_student…
2) Real type : This data type is used to store real numbers i.e. values that might have decimal
places. A real number has this form: integer part.decimal part preceded or not by a sign.
Example of a real variable : weight, height, distance….
3) Boolean type : This data type is used to store the logical data TRUE/FALSE
Example of a boolean variable: married, present, exist.
4) Character type : This dat type characterizes the domain of alphabetic characters (A, B, ..,
Z, a, b, .., z), numbers (0,...,9), symbols (, ; ( ) [ ]. ..), arithmetic operators (+,-,/,*) and
comparison operators (<, >, =). A character is a single letter, number or symbol from above
and is treated as a text, even if it is a number.
Example of a character variable : study_section, driving_icense category, …
5) String type : A string is made of 0, one, two or more characters
Example of a string variable : Decision, Name, Address, Season….
Page 2 sur 2