Sum of Array Elements
# include <iostream>
using namespace std ;
int main(){
int length_of_array ;
cout << "Enter the no. of elements :" ;
cin >> length_of_array ;
int array[length_of_array] ;
for (int i = 0; i < length_of_array; ++i) {
cin >> array[i];
}
int sum{0} ;
for (int i = 0; i < length_of_array; ++i) {
sum = sum + array[i] ;
}
cout << sum ;
return 0 ;
}
Comments
Post a Comment