Day 1
Understanding programs, algorithms, and fundamental programming concepts
This work is licensed under CC BY-NC-SA 4.0
© Way-Up 2025
Allows to use a computer to achieve a task. The program will take input data, will transform them and produce output data, using the computer hardware:
It's only a set of instructions that will produce an expected result, very close to a program but... without any implementation
From the previous description, we can take the cooking recipe example, in such a recipe we have:
Here is the equivalence between cooking recipes and algorithms
It's an action to be executed by the computer. It is a step in the algorithm
| Instructions kinds | Examples (Login on a website) |
|---|---|
| Read/Write | "Read User Credentials from the UI Form" |
| Logical Tests |
|
| Loops |
|
| Variable declaration and initialization |
|
| Function declaration and invocation |
|
It's an action to be executed by the computer. It is a step in the algorithm
| Instructions kinds | Examples (Login on a website) |
|---|---|
| Variable declaration and initialization |
|
| Function declaration and invocation |
|
Why pseudo-code? For several reasons
What is pseudo-code?
Example
Variables A,B as Integer
Begin
A <- 1
B <- A + 3
A <- 3
End
What is a variable
Computer science is the "science" of data organization and processing,
Why is the variable useful?
Variable A as Integer
What to use in pseudo-code? Mainly 4 types of variables
Variable A as Integer
Begin
A <- 34
End
|
Assigns value 1 to A |
|
Assigns String "B" to A |
|
Assigns the value contained in B to A |
|
Assigns the value of B, incremented by 1, B is not affected |
|
concatenate the String "Bonjour " with the value of B and store it in A |
# Case 1
Variables A,B as Integer
Begin
A <- 1
B <- A+3
A <- 3
End
# Case 2
Variables A,B,C as Integer
Begin
A <- 3
B <- 10
C <- A + B
B <- A + B
A <- C
End
# Case 3
Variables A,B,C as String
Begin
A <- "423"
B <- "12"
C <- A + B
End
# Case 4
Write an algorithm allowing to
initialize 2 variables, and
then exchange their values,
this is called "variables permutation".
Read user
...
Display "Bonjour," + user
Variable Age as Integer
Begin
Display "Input your age:"
Read Age
If Age >= 18 Then
Display "Major"
Else
Display "Minor"
EndIf
End
Variable Age as Integer
Begin
Display "Input your age:"
Read Age
If Age >= 18 Then
Display "Major"
ElseIf Age >= 13 Then
Display "Responsible Minor"
Else
Display "Not Responsible Minor"
EndIf
End
it is necessary to repeat operation, without duplicating code!!!, for that purpose we have 3 main categories of loop
The repetition will take place until a particular condition is reached
# While loop
Variable Answer as String
Begin
Display "do you want a coffee? (O/N)"
While not(Answer = "Y" or Answer = "N")
Read Answer
EndWhile
End
# Do-While loop
Variable Answer as String
Begin
Display "do you want a coffee? (O/N)"
Do
Read Answer
While not(Answer = "Y" or Answer = "N")
End
# For loop
Variable DayNumber as Integer
Begin
For DayNumber <- 1 to 15
Display "Day number: " + DayNumber
EndFor
End
demonstration with diagrams.net
Table of 7
7x1 = 7
7x2 = 14
...
7x12 = 84
In the following exercises, the size of the triangle base is configurable
*
**
***
****
*****
*
**
***
**
*
*
***
*****
Example: 5! = 5 x 4 x 3 x 2 x 1 = 120
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Exercise A: Temperature Converter
Write an algorithm that:
1. Asks for temperature in Celsius
2. Converts to Fahrenheit
3. Displays the result
Formula: F = (C × 9/5) + 32
Exercise B: Simple Calculator
Write an algorithm that:
1. Asks for two numbers (A and B)
2. Asks for an operation (+, -, *, /)
3. Performs the operation
4. Displays the result
10
9
8
...
1
Liftoff!
Example for N=12: 1, 2, 3, 4, 6, 12
Write an algorithm that asks for width and height, then displays a rectangle made of asterisks
Example with width=5 and height=3:
*****
*****
*****
Bonus: Make it a hollow rectangle!
*****
* *
*****