C / C++ Program to find the sum of elements from 2 array of integers

Leave a Comment
/* The following program will ask the user to enter the elements of the integer array & then will return the total sum of the array elements. The following program could be expanded to calculate the sum of 'n' number of arrays & also in order to save the memory we can reuse the same array. Of the data is not required further */

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int long a[100],b[100],sum=0;
int d=0,e;
cout<<"Number of Elements in Array 1: ";
cin>>e;
cout<<"Enter For Array 1"<<endl;
while (d<e)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>a[d];
d=d+1;
}
d=0;
while (d<e)
{
sum=sum+a[d];
d=d+1;
}
d=0;
cout<<"\nNumber of Elements in Array 2: ";
cin>>e;
cout<<"Enter For Array 2"<<endl;
while (d<e)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>b[d];
d=d+1;
}
d=0;
while (d<e)
{
sum=sum+b[d];
d=d+1;
}
cout<<"Sum is : "<<sum;
getche();
}


Output:
C / C++ Program to find the sum of elements from 2 array of integers
C / C++ Program to find the sum of elements from 2 array of integers

0 comments: