0

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 10^9+7.

Input Format:

The first line contains a single integer N denoting the size of the array. The next line contains N space separated integers denoting the elements of the array

Output Format:

Print a single integer denoting the product of all the elements of the array Modulo 10^9+7

Constraints:

1≤N≤10^3

1≤A[i]≤10^3

Sample Input:

5

1 2 3 4 5

Sample Output:

120

The code is working fine for the sample testcase but when I submit it on hackerearth it shows segmentation fault.I am unable to identify where the fault is.

I apologize if you find this a trivial question.

The code is:

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

    int main()
    {   
    int i,N;
    int A[i];
    int answer = 1;
    cin >> N ;
    for(int i=0;i<=N-1;i++)
    {   
        cin >> A[i];
        answer = (answer*A[i])%(int)(1000000007);
    }
    cout << answer;
    return 0;
}
A.Vik
  • 93
  • 7

1 Answers1

0

You're just getting a stack overflow. i has undefined value and could be a very large value. Consequently the array is too big to fit in your program's stack address space.

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79