Q:

Hacker Rank solution for Simple Array Sum in C++

0

Problem: Simple Array Sum solution or Simple Array Sum solution in C++ or Simple Array Sum hacker rank solution in Java or Simple Array Sum hacker rank solution c++ or Simple Array Sum hacker rank solution c++ or Simple Array Sum program in c or Simple Array Sum solution in c or Simple Array Sum hacker rank solution in python or Simple Array Sum in java or Simple Array Sum hacker rank solution in c or Hacker Rank Solution For Simple Array Sum in C++ or Simple Array Sum in C++ or Hacker Rank solution for Simple Array Sum in C++.

 

Explanation:- Take multiple inputs of the same type and store the input in an array after that with the help of the third variable add or the sum of all available and print the sum of an array. Here is a huge collection of the program in C, C++, and Java.

 

 

 

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int n,sum=0;
    cin >> n;
 
    vector<int> arr(n);
 
    for(int arr_i = 0;arr_i < n;arr_i++)
    {
       cin >> arr[arr_i];
       // sum+=arr[arr_i];
    }
 
    for(int arr_i = 0;arr_i < n;arr_i++)
    {
        sum+=arr[arr_i];
    }
    cout<<sum;
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now