You are here

C++ program to add two arrays

C++ program to add two arrays.

C++ programming code

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. main()
  5. {
  6.    int first[20], second[20], c, n;
  7.    
  8.    cout << "Enter the number of elements in the array ";
  9.    cin >> n;
  10.  
  11.    cout << "Enter elements of first array " << endl;
  12.  
  13.    for ( c = 0 ; c < n ; c++ )
  14.       cin >> first[c];
  15.  
  16.    cout << "Enter elements of second array " << endl;
  17.  
  18.    for ( c = 0 ; c < n ; c++ )
  19.       cin >> second[c];
  20.  
  21.    cout << "Sum of elements of two arrays " << endl;
  22.  
  23.    for ( c = 0 ; c < n ; c++ )
  24.       cout << first[c] + second[c] << endl;
  25.      
  26.    return 0;
  27. }