Given an array of integers, find the sum of its elements. Keeping in mind that some of those integers may be quite large.
Input Format
The first line contains an integer, ar_count, denoting the size of the array.
The second line contains space-separated integers representing the array’s elements.
Constraints
0<n, ar[i]<=1000
Output Format
Print the sum of the array’s elements as a single integer.
Function Description
The simpleArraySum function in the editor below returns the sum of the array elements as an integer.
simpleArraySum has the following parameter(s): ar: an array of integers
C Program
#include <stdio.h>
#include <stdlib.h>
int simpleArraySum(int ar_count,int ar[]) {
int t=0,SUM=0;
for(t=0;t<ar_count;t++)
{
SUM=SUM+ar[t]; //calculating the sum value
}
return SUM;
}
int main()
{
int ar_count,i,s;
scanf("%d",&ar_count); //Enter array size
int ar[ar_count];
for(i=0;i<ar_count;i++)
{
scanf("%d",&ar[i]); //Enter array elements
}
s=simpleArraySum(ar_count,ar); //store the sum value & call the provided function
printf("%d",s);
return 0;
}