Page 120 - Computer science 868 Class 12
P. 120

Step 8:   If sum < 2 * num then Go to Step 9, else go to Step 10.
                    Step 9:  Display num “is a deficient number”, go to Step 11.
                    Step 10: Display num “is not a deficient number”.
                    Step 11: Stop.
                  8.  Write an algorithm to check if a number is a Krishnamurthy number or not. Krishnamurthy number is a number that is equal
                    to the sum of the factorial of its digits. Let us demonstrate it with an example.
                     Say, Input = 145 is a Krishnamurthy number
                     Now, 1! + 4! + 5!
                     = 1 + (1 × 2 × 3 × 4) + (1 × 2 × 3 × 4 × 5)
                     = 1 + 24 + 120
                     = 145
                Ans.  Step 1:  Start.
                     Step 2:  Accept num.
                     Step 3:  Initialise variable copy to num and sum to 0.
                     Step 4:   Repeat Step 5 to Step 11 while copy > 0.
                     Step 5:  Assign digit = copy % 10.
                     Step 6:  Initialise i and factorial to 1.
                     Step 7:  Repeat Step 8 to Step 9 while i <= digit.
                     Step 8:  Multiply i with factorial and store the product in factorial.
                     Step 9:  Increment i by 1.
                     Step 10: Add factorial to sum.
                     Step 11: Divide copy by 10 .
                     Step 12: If sum = num, then Go to Step 13, else Go to Step 14.
                     Step 13: Display num “is a Krishnamurthy number”, and go to Step 15.
                     Step 14: Display num “is not a Krishnamurthy number”.
                     Step 15: Stop.
                  9.  Write an algorithm to delete any number from position ‘pos’ of a single-dimensional array a[]. Assume that the array is already
                    created.
                Ans.  Step 1:   Start.
                    Step 2:   Initialise i to pos.
                    Step 3:   Repeat Step 4 to Step 5 while i < arraylength - 1.
                    Step 4:   Assign a[i] = a[i+1].
                    Step 5:   Increment i by 1.
                    Step 6:   Decrement the size of the array by 1.
                    Step 7:   Display array.
                    Step 8:   Stop.
                 10.  Write an algorithm to print the sum of each row of a square matrix a[][].
                Ans.  Step 1:  Start.
                     Step 2:  Initialise i to 0.
                     Step 3:  Repeat Step 4 to Step 8 while i < s.
                     Step 4:  Initialise j and rowsum to 0.
                     Step 5:  Repeat Step 6 to Step 7 while j < s.
                     Step 6:  Add a[i][j]to rowsum.
                     Step 7:  Increment j by 1.
                     Step 8:  Display rowsum.
                     Step 9:  Increment  by 1.
                     Step 10: Stop.




                118118  Touchpad Computer Science-XII
   115   116   117   118   119   120   121   122   123   124   125