Complete the function count_odd_even() , which receives number of elements and array as input. Function should count number of even numbers and odd numbers in the array and print it.Input Format:No Need to read any input, as it is predefined.Output Format:Print the count of odd and even as: Odd = ODD_COUNTEven = EVEN_COUNTConstraints:1<=size<=10^9 1<=arr[ind]<=10^15Sample Input 1:1047 41 87 88 95 46 35 66 63 93Sample Output 1:Odd = 7Even = 3Sample Input 2:81 2 3 4 5 6 7 8Sample Output 2:Odd = 4Even = 4
Question
Complete the function count_odd_even() , which receives number of elements and array as input. Function should count number of even numbers and odd numbers in the array and print it.Input Format:No Need to read any input, as it is predefined.Output Format:Print the count of odd and even as: Odd = ODD_COUNTEven = EVEN_COUNTConstraints:1<=size<=10^9 1<=arr[ind]<=10^15Sample Input 1:1047 41 87 88 95 46 35 66 63 93Sample Output 1:Odd = 7Even = 3Sample Input 2:81 2 3 4 5 6 7 8Sample Output 2:Odd = 4Even = 4
Solution
To complete the function count_odd_even(), follow these steps:
- Define the function count_odd_even() with two parameters: num_elements and array.
- Initialize two variables, odd_count and even_count, to 0.
- Use a for loop to iterate through each element in the array.
- Inside the loop, check if the current element is odd or even.
- If the element is odd (i.e., element % 2 != 0), increment the odd_count variable by 1.
- If the element is even (i.e., element % 2 == 0), increment the even_count variable by 1.
- After the loop, print the counts of odd and even numbers using the following format:
- "Odd = odd_count"
- "Even = even_count"
Similar Questions
Even numbersWrite a Python program to print the even numbers from a list.Sample Test CasesTest Case 1:Expected Output:Enter·the·number·of·elements:·2Enter·element:·23Enter·element:·24[24]Test Case 2:Expected Output:Enter·the·number·of·elements:·10Enter·element:·1Enter·element:·2Enter·element:·3Enter·element:·4Enter·element:·5Enter·element:·6Enter·element:·7Enter·element:·8Enter·element:·9Enter·element:·12[2,·4,·6,·8,·12]
Program to ask a user for supplying n different integers and countthe total number of even and odd values among them
Write a C function, which returns the smallest odd number in a given array, and 0 if no such number is found.int smallest_odd(int a[] , int len);
Write a program to print only the even numbers till given NInput FormatA single integer 'N'Output FormatDisplay all the even numbers between 0 and NSample Input10Sample Output0 2 4 6 8 10
Find the sum of even numbers in the given range.Input Format:Accept two integer as inputOutput Format:Print the output as sum of even number available in the given rangeConstraints:1 <= INPUT <= 10^15Sample Input 1:10 20Sample Output 1:90Sample Input 2:30 33Sample Output 2:62
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.