Menu
Coddy logo textTech

Recap - Product Array

Part of the Fundamentals section of Coddy's C++ journey — lesson 63 of 74.

challenge icon

Challenge

Easy

Write 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