CJCoding With Joseph
15free / daySign inCreate account

Sum All Elements

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

Your task is to use the for loop to add up all the elements in the array, then print the total sum.

Inside the loop, add the current element to sum using: sum += nums[i]; (this is the same as sum = sum + nums[i]).

After the loop finishes, print the result in the exact format shown in Expected Output.

Expected Output:

Sum: 150

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