Write a C++ Program to find the Sum of an array elements entered by the user a run time.
Program Code:
#include<iostream>
using namespace std;
int main()
{
int array[50];
int i,n,sum=0;
cout<<"How many elements you want to enter into the array : ";
cin>>n;
cout<<endl;
cout<<"Enter elements into the array : ";
for(i=0;i<n;i++)
{
cin>>array[i];
}
cout<<endl;
cout<<"Sum of all array elements are : ";
for(i=0;i<n;i++)
{
sum = sum + array[i];
}
cout<<"Sum of all array elements are :"<<sum;
return 0;
}
The program output is tested on www.jdoodle.com
Output:
How many elements you want to enter into the array : 8
Enter elements into the array : 1 3 5 2 4 5 2 1
Sum of all array elements are : Sum of all array elements are : 23
Thanks
Mukesh Rajput
Post A Comment:
0 comments: