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 highest and lowest values that can be assigned in the array A.
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.
(i) 13@10@11@10@ (ii) 15$14$12$10$
(iii) 12@11@13@10@ (iv) 12@11@10@10@
Answer:
Possible outputs could be
(i) 13@10@11@10@
and
(iv) 12@11@10@10@
A (Min) = 10
A (Max) = 13
Notes:
randomize();
This will allow random number generation process.
int A[4], C;
Integer array A with four members and and a counter variable C has been declared.
for(C=0; C<4; C++) //This will handle the array in forward order A[C]=random(C+1)+10;
Since value of C would be 0 to 3 in increasing order the possible random values on R.H.S could be 10 to 13. When it is 0 number could be 1o, when it is 3 the number could be 10/11/12/13 on R.H.S. . So the array would be filled by numbers from 10 to 13. The possible value chart could be
index 0 | index 1 | index 2 | index 3 10, 10/11, 10/11/12, 10/11/12/13
for(C=3; C>=0; C–) cout<<A[C]<<“@”;
This will print the possible values in the array but from the last member (at index 3)to the first member at index 0. Based on possible value chart only option (i) and option (iv) are possible. Remember that you are reading array from last to the beginning.
Remember that random number generation is 1 less than the maximum value passed to random function. So random(1) will be 0, random(2) would be 0 or 1, random(3) would 0, 1 or 2, random(4) would 0, 1, 2 or 3
C. Sir| Created: 3-Dec-2018 | Updated: 22-Mar-2026|CBSE12A-2018