โ 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: 50Expected Output:
Index 0: 10 Index 1: 20 Index 2: 30 Index 3: 40 Index 4: 50
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.