You are given an array of integers of size N . Can you find the sum of the elements in the array?
Input
The first line of input consists of an integerN . The next line contains N space-separated integers representing the array elements.
Sample:
6
1 2 3 4 10 11
Output
Output a single value equal to the sum of the elements in the array.
For the sample above you would just print31 since 1+2+3+4+10+11=31 .
------------------------------------------------------------------------------------------------------
Input
The first line of input consists of an integer
Sample:
Output
Output a single value equal to the sum of the elements in the array.
For the sample above you would just print
------------------------------------------------------------------------------------------------------
Simple Array Sum - Hacker Rank Solution
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int a[1000],n=1,i=0,result=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d ",&a[i]);
result=result+a[i];
}
printf("%d",result);
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int a[1000],n=1,i=0,result=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d ",&a[i]);
result=result+a[i];
}
printf("%d",result);
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}