Page 110 - TP_Plus_v4_Class6
P. 110

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





                  108  Plus (Ver. 4.0)-VI
   105   106   107   108   109   110   111   112   113   114   115