Page 88 - 2502_Pakistan-kifayat_C-6
P. 88

Step 5:    Print "The number is odd".

        Step 6:    Stop.

        This algorithm uses the modulus operator (%) to check if the number is divisible by 2. If it is, the number
        is even; otherwise, it is odd.
        Example 5: Find the Maximum of Two Numbers

        Algorithm:

        Step 1:    Start.
        Step 2:    Input the first number (Num1).

        Step 3:    Input the second number (Num2).

        Step 4:    If Num1 > Num2, then go to Step 5; otherwise, go to Step 6.
        Step 5:    Print "Num1".

        Step 6:    Print "Num2".

        Step 7:    Stop.

        In this algorithm, we compare two numbers and select the larger one. If Num1 is greater than Num2, it
        displays Num1; otherwise, it displays Num2.
        Example 6: Check if a Person is Eligible to Vote Based on Age.

        Algorithm:

        Step 1:    Start.

        Step 2:    Input the age (Age).
        Step 3:    If Age >= 18, then go to Step 4; otherwise, go to Step 5.

        Step 4:    Print "You are eligible to vote."

        Step 5:    Print "You are not eligible to vote."
        Step 6:    Stop.

        In this algorithm, it checks whether the person’s age is greater than or equal to 18 (Age ≥ 18). If so, it
        prints "You are eligible to vote"; otherwise, it prints "You are not eligible to vote".


             ITERATION (REPETITION) STATEMENT

        An iteration (or repetition) statement in an algorithm refers to a process where a certain set of
        instructions is repeated multiple times. This allows the algorithm to process or compute a result over
        and over until a specific condition is met. Iteration is essential in programming for tasks that require
        repeating actions, such as looping through items in a list or performing a calculation multiple times.


        Examples of Iteration Statement Algorithms
        Let’s look at some examples to understand the concept of iteration statements.






            86  Premium Edition-VI
   83   84   85   86   87   88   89   90   91   92   93