Given an array of integers, find the sum of its elements.
Input Format
The first line of the input consists of an integer.
The next line contains space-separated integers contained in the array.
Output Format
Return the integer sum of the elements in the array.
Constraints
1<=n<=10
0<=ar[i]<=10^6
Function Description
The aVeryBigSum function in the editor below returns the sum of all array elements.
aVeryBigSum has the following parameter(s): int ar[n]: an array of integers.
Return:
long: the sum of all array elements.
C Program
#include <stdio.h>
#include <stdlib.h>
long aVeryBigSum(int ar_count, long ar[]) {
int i;
long int sum=0;
while (i<ar_count) {
sum=sum+ar[i];
i++;
}
return sum;
}
int main()
{
int ar_count,i=0;
long int s;
scanf("%d",&ar_count);
long int ar[ar_count];
while (i<ar_count) {
scanf("%ld",&ar[i]);
i++;
}
s= aVeryBigSum( ar_count, ar);
printf("%ld",s);
}