Purchase Solution

Passing array as parameter for finding the count of odd numbers

Not what you're looking for?

Ask Custom Question

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:
int myArray[MAX];

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.

Purchase this Solution

Solution Summary

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.

Solution Preview

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++)
{

if(intArray[i]%2 ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C++ Operators

This quiz tests a student's knowledge about C++ operators.