The below code will print the sum of elements in the array passed as the argument.Define the method printArrayElementsSum
int printArrayElementsSum(long int arr[],int N)
{
long int sum=0;
long int len = sizeof(arr)/sizeof(arr[0]);
for(int i=0;i<len;i++)
sum+=arr[i];
printf("%lld",sum);
return sum;
}
int main()
{
int N;
scanf("%d",&N);
int arr[N], index;
for(index=0; index < N; index++){
scanf("%d",&arr[index]);
}
printArrayElementsSum(arr,N);
return 0;
}
If the input is
5
1 2 3 4 5
i need the output as 15
But the above code giving me wrong answer What mistake i have done please rectify it And the arr element is >100000