Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

Q.3. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column. [Assuming the 2D Array to be a square matrix with odd dimension i.e., 3x3, 5x5, 7x7 etc…]

Example : If the array content is
3 5 4
7 6 9
2 1 8
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1

Solution:

void accept(int a[ ][ ],int size)
{ cout<<"Middle Row:";
for (int i=0;i<size;i++)
for(int j=0;j<size;j++)
if (i= = size/2)
cout<<a[i][j]<<’\t’;
cout<<"\n Middle Column:";
for (i=0;i<size;i++)
for(j=0;j<size;j++)
if(j= =size/2)
cout<<a[i][j]<<’\t’;
}

DELHI 2006

Q.1. Write function in C++ which accepts an integer array and size as arguments and assign values into a 2D array of integers in the following format :
If the array is 1, 2, 3, 4, 5, 6
The resultant 2D array is given below
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
If the array is 1, 2, 3
The resultant 2D array is given :
1 2 3
1 2 0
1 0 0
Solution:
void input (int a[ ],int size)
{ int b[size] [size];
for (int i=0;i.<size;i++)
{
for (int j=0;j<size;j++)
{
if(( i+j)>=size)
b[i][j]=0;
else
b[i][j]=a[j];
cout<<b[i][j]<<’\t’;
}
cout<<endl;
}
}

Q.2. An array MAT[30][10] is stored in the memory along column wise with each element occupying 8 bytes of the memory. Find out the Base address and the address of element MAT[20][5] , if the location MAT[3][7] is stored at the address 1000.

Solution: Children, Try this answer as an assignment.

Paper By Mr. Ravi Kiran
Email Id : [email protected]