Page 274 - C++
P. 274

(f)     Look at the following C++ code and find the possible output(s) from
                   the options (i) to (iv) following it. Also, write the maximum values
                   that can be assigned to each of the variables N and M.                          2

                   Note :

                       Assume all the required header files are already being included
                        in the code.

                       The  function  random(n)  generates  an  integer  between  0  and
                        n – 1.

                   void main()

                   {

                       randomize();
                       int N=random(3),M=random(4);

                       int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};


                       for(int R=0; R<N; R++)

                       {
                           for(int C=0; C<M; C++)

                              cout<<DOCK[R][C]<<" ";

                           cout<<endl;
                       }

                   }


                   (i)                                   (ii)

                   1  2  3                               1  2  3

                   2  3  4                               2  3  4
                   3  4  5

                   (iii)                                 (iv)


                   1  2                                  1  2
                   2  3                                  2  3

                                                         3  4
      91                                             4
   269   270   271   272   273   274   275   276   277   278   279