Recap - Product Array
Part of the Fundamentals section of Coddy's C++ journey — lesson 63 of 74.
Challenge
EasyWrite a function named prod which gets an array of double numbers, and the size of the array as arguments and returns the product of all the numbers in the array.
Reminder: product is the multiplication of all the numbers. For example, for [1, 2, 3], return 6 = 1 * 2 * 3.
Try it yourself
#include <iostream>
#include <vector>
double prod(double arr[], int size) {
// Write your code below
}
int main() {
int n;
std::cin >> n;
std::cin.ignore();
double arr[n];
for (int i = 0; i < n; i++) {
double val;
std::cin >> val;
arr[i] = val;
}
double result = prod(arr, n);
std::cout << "Product of array elements: " << result << std::endl;
return 0;
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else