Here is the program to find the sum of list of an array in C++
#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,a[100],sum=0;
cout<<"enter the number of elements\n";
cin>>n;
cout<<"enter the elements of the array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++){
sum=sum+a[i];
}
cout<<"the sum of the elements are \n"<<sum;
getch();
}
Output:
No comments:
Post a Comment