Page 103 - Computer Science Class 11 With Functions
P. 103

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
   98   99   100   101   102   103   104   105   106   107   108