Page 109 - TP_Plus_v4_Class6
P. 109

SOLVING PROBLEMS USING ALGORITHMS AND FLOWCHARTS


                 Some examples are given below to solve the problems using algorithms and flowcharts:
                 Example 1: Write an algorithm and draw a flowchart to check if a given number is even or odd.


                                Algorithm:                               Flowchart:
                 Step 1:  Start.
                                                                             Start
                 Step 2:  Read Number.

                 Step 3:  Check If Number % 2 == 0 Then
                                                                       Read a Number
                          print "Number is even."

                          Else
                                                                              Is
                          print "Number is odd."                                          Yes
                                                                       Number%2==0?             Print Number is even
                 Step 4:  End.

                                                                                No


                                                                     Print Number is odd



                                                                             Stop



                 Example 2: Write an algorithm and draw a flowchart to find the smallest of two numbers A and B.


                                  Algorithm:                               Flowchart:

                 Step 1:  Start.                                              Start

                 Step 2:   Read two numbers and store them
                          in A and B.
                                                                         Read A and B
                 Step 3:   Compare number  A  and  B.  If  A  is

                          less than B, then

                           print "A is smallest"                               if          Yes    Print A is smallest
                                                                              A < B
                          Else
                          print "B is smallest"                                  No

                 Step 4:  End.
                                                                       Print B is smallest



                                                                              Stop








                                                                                             #Algorithmic Intelligence 107
   104   105   106   107   108   109   110   111   112   113   114