# Simple Array Sum Hackerrank Problem coderinme

##### Simple Array Sum

Given an array of N integers, can you find the sum of its elements?

Input Format

The first line contains an integer, N, denoting the size of the array.
The second line contains N space-separated integers representing the array’s elements.

Output Format

Print the sum of the array’s elements as a single integer.

Sample Input

6
1 2 3 4 10 11
Sample Output

31
Explanation

We print the sum of the array’s elements, which is: .

1+2+3+4+10+11=31

``````#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
int n,i,a,sum=0;
scanf("%d",&n);
if(n<=1000){
for(i=0;i<n;++i){
scanf("%d",&a);
sum=sum+a;
}
printf("%d",sum);
return 0;
}
}
``````

###### According to cs.uic.edu

Overview

An array is a collection of data items, all of the same type, accessed using a common name.
A one-dimensional array is like a list; A two dimensional array is like a table; The C language places no limits on the number of dimensions in an array, though specific implementations may.
Some texts refer to one-dimensional arrays as vectors, two-dimensional arrays as matrices, and use the general term arrays when the number of dimensions is unspecified or unimportant.
Declaring Arrays

Array variables are declared identically to variables of their data type, except that the variable name is followed by one pair of square [ ] brackets for each dimension of the array.
Uninitialized arrays must have the dimensions of their rows, columns, etc. listed within the square brackets.
Dimensions used when declaring arrays in C must be positive integral constants or constant expressions.
In C99, dimensions must still be positive integers, but variables can be used, so long as the variable has a positive value at the time the array is declared. ( Space is allocated only once, at the time the array is declared. The array does NOT change sizes later if the variable used to declare it changes. )

Examples:
int i, j, intArray[ 10 ], number;
float floatArray[ 1000 ];
int tableArray[ 3 ][ 5 ]; /* 3 rows by 5 columns */

const int NROWS = 100; // ( Old code would use #define NROWS 100 )
const int NCOLS = 200; // ( Old code would use #define NCOLS 200 )
float matrix[ NROWS ][ NCOLS ];
C99 Only Example:
int numElements;
printf( “How big an array do you want? ” );
scanf( “%d”, &numElements; )
if( numElements <= 0 ) { printf( "Error - Quitting\n" ); exit( 0 ); } double data[ numElements ]; // This only works in C99, not in plain C For more detail

### hasectic

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi