Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 122 - 2620_Birla Open Mind C-6
P. 122

    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

                  Step 5:  Check If N >= 100 then                                             N = N + 1

                          print Sum
                                                                                           Sum = Sum + N
                          Else

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

                                                                                                    Yes

                                                                                              Print Sum

                                                                                                 Stop

                  Example 4: Write an algorithm and draw a flowchart to calculate the factorial of a number.

                                 Algorithm:                                        Flowchart:

                  Step 1:  Start.                                                     Start

                  Step 2:  Read the number n.
                  Step 3:  Let i=1, fact=1                                          Read n

                  Step 4:   Check If i < = n Then Repeat Step
                            5 and 6 until i=n                                     i = 1, fact = 1

                  Step 5:  fact=fact*i
                                                                                       Is
                  Step 6:  i=i+1                                                      i < =     No

                  Step 7:  Print fact                                                  n?

                  Step 8:  End.                                                          Yes
                                                                                  fact = fact*i
                                                                                                             Print fact
                                                                                    i = i + 1

                                                                                      Stop

                      120  Premium Edition-VI

| 117 118 119 120 121 122 123 124 125 126 127 |