Page 48 - IT_V5.0_Class8
P. 48

Step 3:  If NUM % 2 is equal to 0 then
                               Display number is even

                            Else
                               Display number is odd
                  Step 4:  Stop
                  Algorithm 10: Write an algorithm to input marks and display grade based on the given criteria.


                                                            Marks         Grade
                                                       >90               A
                                                       >70 and <=90      B
                                                       >50 and <=70      C

                                                       <50               FAIL

                  Step 1:  Start
                  Step 2:  Input MARKS.
                  Step 3:  If MARKS > 90 then
                                Display Grade: A.
                            Else If MARKS > 70 and MARKS <= 90 then
                                Display Grade: B.
                            Else If MARKS > 50 and MARKS <= 70 then
                                Display Grade: C.

                            Else
                                Display FAIL.
                  Step 4:  Stop
                  Repetition

                  This structure is used for looping, i.e., repeatedly executing a certain block of statements. For
                  example, if we have to calculate the percentage for 5 students, we can repeat the following steps
                  5 times:
                  1.  Input marks for English, Hindi, and Maths of Student 1.

                  2.  Total the marks.
                  3.  Calculate the percentage.
                  4.  Display the percentage.
                  5.  Repeat the steps 1 to 4 to calculate the percentage of other students.

                  Let us write some algorithms based on repetition control structure.
                  Algorithm 11: Write an algorithm to display the natural numbers from 1 to 5.
                  Step 1:  Start
                  Step 2:  Set a variable NUM = 1.

                  Step 3:  Repeat the following steps until NUM reaches 5.
                                Display the value of NUM.
                                   Change NUM = NUM + 1.



                    46    Information Technology (V5.0)-VIII
   43   44   45   46   47   48   49   50   51   52   53