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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: