โ Back to Arrays
Question 97
Count the Elements with a Loop
Count the Elements with a Loop
An array called nums has already been created for you with the values {10, 20, 30, 40, 50}. A variable called count has been initialized to 0.
Your task is to use the for loop to count how many elements are in the array by incrementing count once for each element.
This is different from using sizeof: here you are practicing how to count items as you loop through them. Inside the loop, simply add 1 to count each time.
After the loop, print the result in this exact format:
Count: 5Expected Output:
Count: 5
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.