← Back to Arrays
Question 108
Print Elements with Their Index
Print Elements with Their Index
An array called nums has already been created for you with the values {10, 20, 30, 40, 50}.
Your task is to use the for loop to print each element along with its index position. Each line should follow this exact format:
Index 0: 10
The loop variable i already represents the index, and nums[i] gives you the value at that index. You just need to combine them in a single cout statement.Expected Output:
Index 0: 10 Index 1: 20 Index 2: 30 Index 3: 40 Index 4: 50
= 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.