Simple Array Sum

Problem Statement

You are given an array of integers of size N. You need to print the sum of the elements of the array.

Input Format
The first line of the input consists of an integer N. The next line contains N space-separated integers describing the array.

Constraints
1N1000
0A[i]1000

Output Format
Output a single value equal to the sum of the elements of the array.

Sample Input

6
1 2 3 4 10 11

Sample Output

31

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

Solution

  
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define max 1000
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n,temp,sum;
    cin>>n;
    while(n--){
        cin>>temp;
        sum+=temp;
    }
        cout<<sum;
    return 0;
}


Leave a Reply