Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 88 - 2505_CoreGPT(Podar)_Flipbook_C6
P. 88

    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 whether a given number is
                      even or odd.
                                    Algorithm:                             Flowchart:
                      Step 1  Start.
                      Step 2  Read Number.                                    Start

                      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  Stop.

                                                                                 No

                                                                      Print Number is odd

                                                                              Stop

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

                                    Algorithm:                               Flowchart:
                      Step 1  Start.
                                                                                 Start
                      Step 2   Read two numbers and store
                               them in A and B.
                      Step 3   Compare numbers A and B. If                  Read A and B
                               A is less than B, then
                                print "A is smallest"
                                                                                  if
                               Else                                                          Yes
                                                                                A < B                Print A is smallest
                               print "B is smallest"

                      Step 4  Stop.
                                                                                    No

                                                                          Print B is smallest

                                                                                Stop

                     86     Premium Edition-VI

| 83 84 85 86 87 88 89 90 91 92 93 |