Important Questions

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

CBSE CLASS XII

Q.1. Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in reverse. Example:If an array of nine elements initially contains the elements as 4, 2, 5, 1, 6, 7, 8, 12, 10 Then the function should rearrange the array as 10,12, 8, 7, 6, 1, 5, 2,

Solution:

void receive(int A[ ], int size)
{ int temp;
for(i=0,j=size-1;i<size/2;i++,j--)
{ temp=A[i];
A[i]=A[j];
A[j]=temp;
}
}//end of receive function.

Q.2. An array Arr[40][10] is store in the memory along the column with each element occupying 4 bytes. Find out the base address of the location Arr[3][6] if the location Arr[30][10] is stored at the address 9000.

Solution:

Children, Try this answer as an assignment.

Q.3. Write a function in C++ to print the product of each column of a two dimensional array
passed as the arguments of the function.
Example : If the two dimensional array contains
Then the output should appear as:
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 =240
void receive(int A[ ][ ],int r,int c)
{ int i,j,B[c];
for(i=0;i<c;i++)
B[i]=1;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
B[j]=B[j]*A[i][j];
for(i=0;i<c;i++)
cout<<”\nProduct of Column “<<i+1<<” = “<<B[i];
}

OUTSIDE DELHI 2008

Q.1. Write a function in C++, which accepts an integer array and its size as arguments and swap the elements of every even location with its following odd location.

Example :

If an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 then the function should rearrange the array as 4,2,6,1,7,5,23,9,10 void SwapArray(int A[ ], int N)
{ int i,j,temp;
/* cout<<”\nThe elements before doing the desired alterations…”;
for(i=0;i<N;i++)
cout<<A[i]<<’\t’; */
for(i=0;i<N-1;i+=2)
{ temp=A[i];
A[i]=A[i+1];
A[i+1]=temp;
}
/* cout<<”\nThe elements after completed the desired alterations…”;
for(i=0;i<N;i++) cout<<A[i]<<’\t’; */
}

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