Question of 97
Q.Write a user-defined function NoTwoThree(int Arr[], int N) in C++, which should display the value of all such elements and their corresponding locations in the array Arr (i.e. the array index), which are not multiples of 2 or 3. N represents the total number of elements in the array Arr, to be checked. Example : If the array Arr contains index: 0 1 2 3 4 value: 25 8 12 49 9 Then the function should display the output as : 25 at location 0 49 at location 3
(OR)
Write a user-defined function ReArrange(int Arr[], int N) in C++, which should swap the contents of the first half locations of the array Arr with the contents of the second half locations. N (which is an even integer) represents the total number of elements in the array Arr. Example : If the array Arr contains the following elements (for N = 6) index: 0 1 2 3 4 5 value: 12 5 7 23 8 10 Then the function should rearrange the array to become index: 0 1 2 3 4 5 value: 23 8 10 12 5 7 NOTE : DO NOT DISPLAY the Changed Array contents. Do not use any other array to transfer the contents of array Arr.
CBSECBSE Class XII Board 2019Subjective· 3mImportance★★★★★
0% · 0/97 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a) traverses the array and prints each element that is a multiple of neither 2 nor 3 together with its index; Part (b) swaps the first-half and second-half elements in place without a second array.
Part (a)
An element must be shown only if it is not a multiple of 2 and not a multiple of 3, i.e. Arr[i]%2 != 0 && Arr[i]%3 != 0.
void NoTwoThree(int Arr[], int N) {
for (int i = 0; i < N; i++)
if (Arr[i] % 2 != 0 && Arr[i] % 3 != 0)
cout << Arr[i] << " at location " << i << endl;
}
Trace on {25,8,12,49,9}: 25 (odd, not /3) → print; 8 (/2) skip; 12 (/2,/3) skip; 49 (not /2, not /3) → print; 9 (/3) skip.
25 at location 0
49 at location 3 …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.