Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
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.
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
randomize(); //This allows the code to run random function
int N=random(3),M=random(4);
HereΒ N can contain value 0,1,2 and M can contain value 0,1,2,3
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
This is 3×3 two dimensional array declaration along with initial values
for(int R=0; R<N; R++) {Β //This is external loop for counting rows up to maximum of N
for(int C=0; C<M; C++)Β //This is internal loop for counting columns up to maximum of M cout<<DOCK[R][C]<<” “; // This prints the array member cout<<endl;Β }//This allows to go to next row
Watch that due to maximum possible value of row count which is 2 any possible output can not go above 2 rows so options (ii) and (iii) are correct and (i) and (iv) are incorrect as they are three row outputs.
Special Note:
While testing the actual output of this program one may get 0 row output (no output) 1 row output or two row output with 0 columns, 1 columns, 2 columns or 3 columns
So please be prepared to see nothing as output. Once may have to run this program again and again to get desired output.
C. Sir| Created: 7-Dec-2018 | Updated: 22-Mar-2026|CBSE12A-2017