Page 75 - Digicode_AI_class_8
P. 75
To reach the final output, you need to follow the algorithm step by step.
Explanation: Read the two numbers “num1 and num2” that needs to be swapped. Assign the value
of num1 to a temporary variable called “temp” and the value of num2 to num1. Then, assign value of
“temp” to num2. Finally, Print the values of num1 and num2 which are now swapped.
If you follow the steps correctly in sequence, you will achieve the output. Skipping any step from this
sequence or altering the sequence will lead to errors in the program or generation of wrong output.
This is how sequencing in programming works.
Let’s take the example of Selection:
Example: Pseudocode to check if the citizen is senior citizen or not on the basis of age entered by
the user. (Person is considered a senior citizen if his/her age is above 60 years old.)
int age = 61:
if (age>=60)
print(“Person is a senior citizen”):
else
print(“Person is not a senior citizen”):
Explanation: In this the pseudocode will check if the person is a senior citizen or not on the basis of
age entered by the user.
If you follow the sequence of pseudocode, you will see that the program makes a “selection” of
which flow to enter depending on the age defined in the program.
If the age is more than or equal to 60, the program enters the if block. If the age is less than 60, the
program enters else block.
Example: Flowchart to print all the natural numbers from 1 to 100.
Start
Input N
FOR 1<num*2
IF
1%2 !=0
SUM = SUM+1
Print SUM
Stop
Advanced MakeCode Arcade 73

