I have to print product of elements of array A mod 10^9+7
,there should N
elements in array and the constraints are 1<=N<=10^3
and 1<=A[i]<=10^3
.
The code I wrote
#include<stdio.h>
int main()
{
int N, pro = 1;
scanf("%i", &N);
int arr[N];
for (int i = 0; i<N; i++) {
scanf("%i", &arr[i]);
pro = (pro*arr[i]) % (1000000007);
}
printf("%i", pro);
}
gave wrong answer but when I replaced int arr[N]
to long int arr[N]
and changed its precision specifier to %li
it gave correct output.
My confusion is when the upper limit of array's elements is only 10^3
then why using long int worked and not just int
.
i am using 64 bit windows OS and the inputs which i am giving are 3 digit numbers
as array elements for example 568,253 etc without any 0 in beginning.