← Back to Arrays
Question 119
Multiply All Elements Together
Multiply All Elements Together
An array called nums has already been created for you with the values {2, 3, 4, 5}.
Your task is to multiply all the elements together and print the product.
This is similar to summing, but instead of adding each element to a running total, you multiply. The key difference is that you must initialize your result variable to 1, not 0. If you start at 0, multiplying anything by 0 will always give 0.
2 × 3 × 4 × 5 = 120
Print the result in this exact format:
Product: 120Expected Output:
Product: 120
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.