Page 72 - Digicode_AI_class_6
P. 72

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


                                                                   Flowchart:
                            Algorithm:
             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

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

                                                                         No
                     print "B is smallest"

             Step 4   End.                                     Print B is smallest


                                                                      Stop


            Example 3: Write an algorithm and draw a flowchart to add first 100 natural numbers.
                             Algorithm:                                              Flowchart:

             Step 1   Start.
                                                                                          Start
             Step 2   Let Sum = 0 and N = 0
                                                                                    Sum = 0, N = 0
             Step 3   N = N + 1

             Step 4   Sum = Sum + N
                                                                                        N = N + 1
             Step 5   Check If N >= 100 then

                     print Sum                                                       Sum = Sum + N

                     Else
                                                                                           Is
                                                                                 No
                     Go to Step 3.                                                        N >=
                                                                                          100?
             Step 6   End.
                                                                                              Yes

                                                                                        Print Sum


                                                                                          Stop







                 70    DigiCode AI-VI
   67   68   69   70   71   72   73   74   75   76   77