Important Questions

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

CBSE CLASS XII

OUTSIDE DEHI 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 8, 10, 1, 3, 17, 90, 13, 60
The function should rearrange array as 17, 90, 13, 60, 8, 10, 1, 3

Solution: Refer Delhi 2005 Q.3a.

Q.2. An array Arr[35][15] 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[20][5] , if the location Arr[2][2] is stored at the address 3000.

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 3 or divisible by 5 present in a 2D array passed as the argument of the function.

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

DELHI 2004

Q.1. Define the function SwapArray(int[ ], int),that would expect a 1D integer array NUMBERS and its size N. the function should rearrange the array in such a way that the values of that locations of the array are exchanged. (Assume the size of the array to be even).
Example :
If the array initially contains {2, 5, 9, 14, 17, 8, 19, 16}
Then after rearrangement the array should contain {5, 2, 14, 9, 8, 17, 16, 19}

Solution:
void SwapArray(int NUMBERS[ ], int N)
{ int i,j,temp;
/* cout<<”\nThe elements before doing the desired alterations…”;
for(i=0;i<N;i++)
cout<<NUMBERS[i]<<’\t’; */
for(i=0;i<N-1;i+=2)
{ temp=NUMBERS[i];
NUMBERS[i]=NUMBERS[i+1];
NUMBERS[i+1]=temp;
}
/* cout<<”\nThe elements after completed the desired alterations…”;
for(i=0;i<N;i++)
cout<<NUMBERS[i]<<’\t’; */
}

Q.2. An array ARR[5][5] is stored in the memory with each element occupying 3 bytes of space. Assuming the base address of ARR to be 1500, compute the address of ARR[2][4], when the array is stored :

Solution: Children, Try this answer as an assignment.

Q.3. Write a function in C++ to find the sum of diagonal elements from a 2D array of type float. Use the array and its size as parameters with float as its return type.

Solution:
float diasum(float A[ ][ ],int R,int C)
{ int i,j;
float Dsum=0.0;
for(i=0;i<R;i++)
for(j=0;j<C;j++)
if((i= = j)| | (i+j)= =(size-1))
Dsum=Dsum+A[i][j];
return Dsum;
}

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