Simple Array Sum || HackerRank
Problem name: Simple Array Sum
Judge: HackerRank
Problem link: Simple Array Sum
Solution on GitHub: Simple Array Sum
[At first you should try to solve the problem on your own. This will increase your thinking power and the ability to solve the program will increase. And if you copy directly from here, you will not learn anything. So my advice is to try to solve it yourself first. If not then check this code. Once you understand the code, do it yourself. Don't copy from here.
Best of luck]
Solution in C++/Cpp
#include <iospace>
using namespace std;
int main()
{
int n, i, sum = 0;
cin >> n;
int array[n];
for (i = 0; i < n; i++)
{
cin >> array[i];
sum = sum + array[i];
}
cout << sum << endl;
return 0;
}
