Page 74 - Touchcode_C8_Flipbook
P. 74

Step 3:  num1 = num2

                   Step 4:  num2 = temp

                   Step 5:  PRINT num1, num2



                  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:
                                                                                                       Subject Enrichment

                   Example 2: 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.)

                   Program Start
                   set int age to 61

                   if (age>=60)
                     print(“Person is a senior citizen”):

                   else
                      print(“Person is not a senior citizen”):

                   Program End



                  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.





                   72     Touchcode-VIII
   69   70   71   72   73   74   75   76   77   78   79