Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 80 - 2617_JSSPS_C-6
P. 80

    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.
                                                                           Read A and B
                  Step 3:   Compare numbers A and B. If A is
                            less than B, then

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

                  Step 4:  Stop.
                                                                         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

                  Step 3:  N = N + 1                                                         Sum = 0, N = 0

                  Step 4:  Sum = Sum + N
                                                                                               N = N + 1
                  Step 5:  Check If N >= 100 then
                            print Sum
                                                                                            Sum = Sum + N
                            Else
                                                                                                   Is
                            Go to Step 3.                                                No      N >=

                  Step 6:  Stop.                                                                 100?

                                                                                                     Yes
                                                                                               Print Sum

                                                                                                  Stop

                     78     Premium Edition-VI

| 75 76 77 78 79 80 81 82 83 84 85 |