Page 228 - C++
P. 228
(e) Find and write the output of the following C++ program code : 3
Note : Assume all required header files are already being included in the program.
void main()
{
int A[]={10,12,15,17,20,30};
for(int i = 0; i<6; i++)
{
if(A[i]%2==0)
A[i] /= 2;
else if(A[i]%3==0)
A[i] /= 3;
if(A[i]%5==0)
A[i] /=5;
}
for(i = 0; i<6; i++)
cout<<A[i]<<”#”;
}
(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 R and C. 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 R=random(3),C=random(4);
int MAT[3][3] = {{10,20,30},{20,30,40},{30,40,50}};
for(int I=0; I<R; I++)
{
for(int J=0; J<C; J++)
cout<<MAT[I][J]<<" ";
cout<<end1;
}
}
(i) (ii)
10 20 30 10 20 30
20 30 40 20 30 40
30 40 50
(iii) (iv)
10 20 10 20
20 30 20 30
30 40
91/1 3 [P.T.O.