Question: Write a C + + function called goodArray that takes a reference to an integer array called ar and does the following: 1 . Prints

Write a C++ function called goodArray that takes a reference to an integer array called ar and does the following:
1. Prints "Good" if there is an element in the array, called "BigNumber," whose value equals the sum of all even elements (excluding itself).
2. Prints "VeryGood" if you can swap the "BigNumber" with any other element to make the array a palindrome (if the array is printed from left to right or printed from right to left the result is the same).
3. Otherwise, prints "NO"
For example:
1. For the array arr =[1,2,4,2], the output is "Good" because an[2]=4 is equal to
the sum of all even elements (ar[2]- an [1]+ arr[31).
2. For the array ar =[2,3,2,3,41, the output is "VeryGood" because an[4]=4 is
equal to the sum of all even elements. Additionally, swapping it with an(2] makes the array a palindrome.
3. For the array arr =[1,2,3,4,5], the output is "NO". because there is no
BigNumber.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!