C++ program to add two arrays:This program first input some element of two array and perform the addition work correspondingly along with arrays element, that means first element of first array add with first element of second array and print the sum on output screen.
C++ program to add two arrays
#include<iostream>
main()
{
int first[20], second[20], c, n;
cout << "Enter the number of elements in the array ";
cin >> n;
cout << "Enter elements of first array " << endl;
for ( c = 0 ; c < n ; c++ )
cin >> first[c];
cout << "Enter elements of second array " << endl;
for ( c = 0 ; c < n ; c++ )
cin >> second[c];
cout << "Sum of elements of two arrays " << endl;
for ( c = 0 ; c < n ; c++ )
cout << first[c] + second[c] << endl;
return 0;
}
Output
Enter the number of elements in the array 5
Enter elements of first array 3 4 2 6 7
Enter elements of second array 5 3 7 5 2
Sum of elements of two arrays 8 7 9 11 9