This question has three parts.
1. Write a function that takes an array of int as a parameter and returns a count of odd numbers in the array.
Assume the array has MAX elements where MAX is a global constant int. That means that before all of the functions
there is a declaration like:
const int MAX = 10;
And arrays are declared like:
2. Write a function that takes an array of int as a parameter and returns the sum of odd numbers in the array.
Assume the array has MAX elements where MAX is a global constant int.
3. Rewrite your answer to the previous question as a recursive function.© BrainMass Inc. brainmass.com October 10, 2019, 8:21 am ad1c9bdddf
Check the attached .cpp file for inline comments.
1. Solution for part 1
int oddNum(int intArray)
int count = 0;
for(int i =0; i<=MAX; i++)
The code is very simple and easy to understand, written in C++. A picture as well as .cpp file is also attached with inline comments. The code can easily be modified. It has three separate functions for each of the questions part. First two functions uses a for loop to scan all the elements within an array, counts odd numbers and sums them up, while the third function uses a 'while' loop to process elements in given array.