Find Product

You have been given an array A of size N consisting of positive integers. You need to find and print the product of all the number in this array Modulo 

109+7.

Example:

Input:  n = 5, a = [1,2,3,4,5]
Output: 120

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long long findProduct(long long nlong long a[])
{
    long long ans = 1;
    for (long long i = 0i < ni++)
    {

        ans = (ans * a[i]) % (1000000007);
    }
    return ans;
}
int main()
{
    long long n = 5;
    long long a[n] = {12345};

    cout << findProduct(na<< "\n";

    return 0;
}


No comments:

Post a Comment