Simple array sum
Code
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; //array size
cin>>n;
int a[n]; //array elements
int sum=0; //to store sum
for(int i=0;i<n;i++){ //reading array elements
cin>>a[i];
}
for(int i=0;i<n;i++){ //to calculate sum
sum=sum+a[i];
}
cout<<sum; //print the sum
return 0;
}
Simple Array Sum HackerRank Solution in C++
Simple Array Sum HackerRank Solution in Cpp
Simple Array Sum HackerRank Answer
0 Comments