Answer:
Following are the program which is given below:
#include <iostream> //defining header file
using namespace std;
int main() //defining main method
{
int a[10],i=0,sum=0,n2; //defining integer variables
cout<<"Enter total element you want to insert: "; //print message
cin>>n2; //input values
for(i=0;i<n2;i++) //defining loop to input value from user end
{
cin>>a[i]; //input values
}
cout<<"array elements: "; //print message
for(i=0;i<n2;i++) //defining loop for print value
{
cout<<a[i]<<",";
}
for(i=0;i<n2;i++) //defining loop to calculate sum
{
sum=sum+a[i];//add all values
}
cout<<endl<<"sum: "<<sum; //print sum
return 0;
}
Output:
Enter total element you want to insert: 6
7
9
10
2
18
6
array elements: 7,9,10,2,18,6,
sum: 52
Explanation:
The description of the program code as follows: