Thursday 25th April 2024
REGISTRATION
Online Fashion Store

CBSE Computer Science - Revision Tour(Solved)

CBSE Guess > eBooks > Class XII > CBSE Computer Science Arrays Solved Revision Tour By Mr. Ravi Kiran

COMPUTER SCIENCE ARRAYS

Previous Index Next

OUTSIDE DELHI 2008:

3.a) Write a function in C++, which acceptsan 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’; */
}

3.b) An array Arr[50][10] is store in the memory along the row with each element occupying 2 bytes. Find out the Base address of the location Arr[20][50], if the location Arr[10][25] is stored at the address 10000.

Solution: Children, Try this answer as an assignment.

3.d) Write a function in C++ to print the product of each row of a two dimensional array passed as the arguments of the function

Example: if the two imensional array contains Then the output should appear as:

Product of Row 1 = 8000
Product of Row 2 = 6000
Product of Row 3 =3600
Product of Row 4 = 2400

void receive(int A[ ][ ],int r,int c)
{ int i,j,B[r];
for(i=0;i<r;i++)
B[i]=1;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
B[i]=B[i]*A[i][j];
for(i=0;i<r;i++)
cout<<”\nProduct of Row “<<i+1<<”
= “<<B[i];
}

DELHI 2007:

3.a) Write function in C++ which accepts aninteger array and size as arguments and replaces elements having odd values with thrice its value and elements having even values with twice its value. Example : if an array of five elements initially contains elements as 3, 4, 5, 16, 9
The the function should rearrange the content of the array as 9, 8, 75, 32, 27

Solution:

void manipulate (int a[ ],int size)
{ for (i=0;i<size;i++)
{ if (a[i]%2= =1)
a[i]=a[i]*3;
else
a[i]=a[i]*2;
cout<<a[i]<<’,’;
}
}


Previous Index Next

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )