← Back to Arrays
Question 104
Count Odd Numbers
Count Odd Numbers
An array called nums has already been created for you with the values {10, 15, 20, 25, 30}. A variable called count has been initialized to 0.
Your task is to use the for loop to count how many odd numbers are in the array.
A number is odd if dividing it by 2 leaves a remainder of 1. You can check this using: nums[i] % 2 != 0. The % operator gives the remainder: if it's not 0, the number is odd.
In this array, the odd numbers are 15 and 25, so the count should be 2.
Print the result in the exact format shown in Expected Output.Expected Output:
Odd count: 2= newline. No newline after the last line.
Hints2 available
Sign in to use hintsTopics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.