CJCoding With Joseph
15free / daySign inCreate account

Sum Even Numbers Only

An array called nums has already been created for you with the values {10, 15, 20, 25, 30}. A variable called sum has been initialized to 0.

Your task is to use the for loop to add up only the even numbers in the array. Skip the odd numbers.

This combines two things you've already practiced:
1. Checking if a number is even: nums[i] % 2 == 0
2. Adding to a running total: sum += nums[i]

The even numbers in this array are 10, 20, and 30. Their sum is 60.

Print the result in the exact format shown in Expected Output.

Expected Output:

Even sum: 60

= newline. No newline after the last line.

Hints2 available
Topics:
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.