Question

In: Computer Science

Develop a C++ function to find the number of even and odd integers in a given...

Develop a C++ function to find the number of even and odd integers in a given array of integers

Pass in an array of integers
Pass in the size of the array of integers
Pass in a reference parameter for the number of even values
Pass in a reference parameter for the number of odd values
The function doesn't return anything
Develop a C++ program to test your function

Solutions

Expert Solution

C++ code:

#include <iostream>
using namespace std;
//initializing oddEven function for finding odd and even number count
void oddEven(int numbers[],int n,int &even,int &odd){
//looping till n
for(int i=0;i<n;i++){
//checking if the number is even
if(numbers[i]%2==0)
//incrementing even number count
even++;
else
//incrementing odd number count
odd++;
}
}
int main()
{
//initializing even and odd number number count as 0
int even=0,odd=0;
//initializing a sample numbers list
int numbers[] {1,2,3,4,5,6,7,8,9};
//calling oddEven function
oddEven(numbers,9,even,odd);
//printing Even number count
cout<<"Even number count="<<even<<endl;
//printing Odd number count
cout<<"Odd number count="<<odd<<endl;
return 0;
}


Screenshot:


Output:


Related Solutions

Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Write a C++ program to find the number of pairs of integers in a given array...
Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.
Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number....
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number. The main function is given: int main(){     int number;     cout << "Check number input: ";     cin >> number;     cout << "The input number " << number << " is " << checkEvenOrOdd(number) << endl;     return 0; } simple c++ code please
Prove that every natural number is odd or even.
Prove that every natural number is odd or even.
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
write code to count the number of odd integers in an array of 100 random integers...
write code to count the number of odd integers in an array of 100 random integers in the range [0,99].
A function is odd function if f (-x) = - f(x). A function is even function...
A function is odd function if f (-x) = - f(x). A function is even function if f(-x) = f(x). f(x) = sin (x) and f(x) = x are examples of odd functions and f(x) = cos x and f(x) = e^ (-x)^2 are examples of even functions. Give two more examples of even functions and two more examples of odd functions. Show that for odd functions f (x), integral of f(x) from negative infinity to infinity = 0 if...
Task 1: Remove Number Complete the function remove number such that given a list of integers...
Task 1: Remove Number Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2: Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT