CJCoding With Joseph
15free / daySign inCreate account

Calculate the Average

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

Your task is to:
1. Use the for loop to add up all the elements in the array.
2. After the loop, calculate the average by dividing the sum by the number of elements (5).
3. Print the result in this exact format: Average: 30

The average is the total sum divided by how many numbers there are. Since 10 + 20 + 30 + 40 + 50 = 150, and there are 5 elements, the average is 150 / 5 = 30.

Expected Output:

Average: 30

= 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.