Important Questions

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

CBSE CLASS XII

OUTSIDE 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 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
If the array is 1, 2, 3
The resultant 2D array is given :
1 0 0
1 2 0
1 2 3

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)
b[i][j]=0;
else
b[i][j]=a[j];
cout<<b[i][j]<<’\t’;
}
cout<<endl;
}
}

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

Solution: Children, Try this answer as an assignment.

DELHI 2005

Q.1. )Write a function in C++ which accepts an integer array and its size as arguments and exchanges the values of first half side elements with the second half side elements of the array.

Example :
If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10
The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6

Solution:
void change(int a[ ],int size)
{
int i,j,temp;
for(i=0,j=size/2;j<size;i++,j++)
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}

Q.2. An array Arr[15][35] is stored in the memory along the row with each of its element occupying 4 bytes . Find out the Base address and the address of element Arr[2][5] , if the location Arr[5][10] is stored at the address 4000.

Solution: Children, Try this answer as an assignment.

Q.3. )Write a function in C++ to print sum of all values which either are divisible by 2 or divisible by 3 present in a 2D array passed as the argument of the function.

Solution:
void Sum(int A[ ][ ],int R,int C)
{ int i,j,S=0;
for(i=0;i<R;i++)
for(j=0;j<C;j++)
if(A[i][j]%2= = 0 ||A[i][j]%3= = 0)
S=S+A[i][j];
cout<<”\nThe Sum of all the values which are divisible by 2 or 3 in the array = “<<S;
}

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