Page 115 - Computer Science V2.0 Class 11
P. 115

Example: Write a pseudocode and draw the flowchart to compute the factorial of a number.
                 Input:
                     num: the number whose factorial is required

                 Process:
                     Compute the product of numbers 1 to num.
                 Output:
                     Product as the factorial of given number
                 input num
                 product = 1
                 for i = 1 to num
                      product = product * i
                 end-for
                 Print product
                 The flowchart of the above pseudocode is as follows (Fig 4.12):


                                                  Start



                                                input num



                                               product = 1





                                                                              i = 1




                                                          False
                                                                             i< = num



                                                                                  True

                                                                         product = product*i


                                                                              i = i + 1




                                                 print product




                                                     Stop

                                              Fig 4.12: Flowchart to compute the factorial of a number
                 Finally, suppose you are required to find the average marks of students in a class. The marks obtained by different
                 students are entered by the user one by one, and the end of the input is indicated by entering a negative integer.

                                                                                                     Problem Solving  101
   110   111   112   113   114   115   116   117   118   119   120