Page 402 - computer science (868) class 11
P. 402

if(i>n)
                            System.out.println();
                        else if(j>i)
                        {
                            System.out.println();
                            print(n,i+1,i+1);
                        }
                        else
                        {
                            System.out.print(j);
                            print(n,i,j+1);
                        }
                    }
                  4.  The following functions show() and calling() are part of some class. Assume that the parameter n is greater than 1 when the
                    function is invoked. It returns the value 1 when true otherwise it returns 0. Show the dry run/working.    [ISC 2008]
                    void calling()
                    {
                        int f=2;
                        show(n,f);
                    }
                    int show(int n, int f)
                    {
                        if(n==f)
                            return 1;
                        if(n%f==0 || n==1)
                            return 0;
                        else
                            return(show(n,f+1));
                    }
                     (i)  What will the function show() return when the value of n is 11?
                    (ii)  What will the function show() return when the value of n is 27?
                     (iii)  In one line, state what function show() is doing.
                  5.  The following function is a part of some class. What will the method return if n=10? Show working/dry run.
                    int func(int n)
                    {
                        if (n == 0)
                            return 0;
                        else if (n == 1)
                            return 1;
                        else if (n == 2)
                            return 1;
                        else
                            return 2*func(n-2) + func(n-3);
                    }
              D.  Unsolved Programs:

                  1.  Design a class Armstrong to check if a given number is a Armstrong number or not. An Armstrong number is a positive m-digit
                    number that is equal to the sum of the m  powers of their digits. For example,
                                                    th
                         3
                            3
                                3
                     153: 1  + 5  + 3  = 1 + 125 + 27 = 153 (Digit count of 153 is 3. So, cube of all the digits is taken)
                         3
                                3
                     371: 3  + 7  + 1  = 27 + 343 + 1 = 371 (Digit count of 371 is 3. So, cube of all the digits is taken)
                            3
                                 4
                             4
                          4
                     1634: 1  + 6  + 3  + 4  = 1 + 1296 + 81 + 256 = 1643 (Digit count of 1643 is 4. So, 4  power of digits is taken)
                                                                                   th
                                    4
                     Some of the members of the class are given below:
                     Class name                  :   Armstrong
                     Data Members/Instance variables
                     num                         :  To store the number
                     Member Methods/Member functions
                     void getnum()               :  Accepts number in num
             400 400  Touchpad Computer Science-XI
   397   398   399   400   401   402   403   404   405   406   407