Page 428 - Cs_withBlue_J_C11_Flipbook
P. 428

(i)   What will be the output of fun1() when the value of s[ ] = {‘J’, ‘U’, ‘N’, ‘E’} and x = 1?
                     (ii)  What will be the output of fun2( ) when the value of n = “SCROLL”?
                  2.  The following function is a part of some class. What will the method return if x=29? Show working/dry run.
                    int generate(int x)
                    {
                        if(x<=2)
                            return x;
                       else
                             return generate(x/2)+generate(x/2+1);
                    }
                  3.  The following function is a part of some class. What will the method print if n=5, i=4 and j=3? Show working/dry run.
                    void print(int n, int i, int j)
                    {
                        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)


             426 426  Touchpad Computer Science-XI
   423   424   425   426   427   428   429   430   431   432   433