โ Back to Arrays
Question 116
Sum of Elements at Even Indices
Sum of Elements at Even Indices
An array called nums has already been created for you with the values {10, 20, 30, 40, 50}.
Your task is to add up only the elements that are at even index positions (indices 0, 2, and 4) and print the sum.
This is different from summing even numbers: here you are checking whether the index is even, not the value. The elements at even indices are:
- Index 0: 10
- Index 2: 30
- Index 4: 50
Their sum is 90.
Print the result in this exact format:
Sum at even indices: 90Expected Output:
Sum at even indices: 90
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.