Page 46 - iprime_V2.2_class8
P. 46

Flowchart:                                         Example 2:  Write an algorithm and draw  a
                                                                                  flowchart to check whether a given
                               Start                                              number is even or odd.

                                                                     Algorithm
                                                                     Step 1  Start
                              Read n
                                                                     Step 2  Read the number n
                                                                     Step 3  Check if n % 2 == 0 then
                                                                             print "Number is Even."
                                i = 1
                                                                             Else
                              fact = 1
                                                                             print "Number is Odd."
                                                                     Step 4  Stop
                                                                     Flowchart:
                                 Is
                                               No
                              i < = n?                                                     Start




                                    Yes
                                                                                          Read n
                            fact = fact*i
                                                   Print fact


                                                                                            Is
                              i = i + 1                                                 n % 2==0




                                                                                     Yes            No
                               Stop


                                                                         Print "Number            Print "Number
                                                                            is Even."                 is Odd."






                                                                                           Stop



                      Reb             t



                           Algorithm is a set of steps in a sequential manner to solve a problem or to complete
                          a task.
                           Flowchart is a graphical representation of the sequence of operations in an information

                          system or program.
                           Flowcharts use standard symbols to represent input or output operations.



                  44     iPRIME (Ver. 2.2)–VIII
   41   42   43   44   45   46   47   48   49   50   51