Relative Content

Tag Archive for c++arraysfor-loopsuminteger

Sum of the elements present in an array

//Adding all the Elements in an array and displaying their sum #include<iostream> using namespace std; int main(){ int n; cout<<“Enter the number of Elements in an array: “; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[n]; } int sum; for(int i=0;i<n;i++){ sum+=a[n]; } cout<<sum; } Output: Enter the number of Elements in an array: 2 1 5 […]