21xrx.com
2024-03-28 21:44:17 Thursday
登录
文章检索 我的文章 写文章
将两个数组相加的C++程序
2021-07-08 15:22:47 深夜i     --     --
C + +

C++ 程序添加两个数组。

C++编程代码

#include<iostream>
using namespace std;


int main()
{
  int first[20], second[20], sum[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 the arrays:" << endl;

  for (c = 0; c < n; c++) {
    sum[c] = first[c] + second[c];
    cout << sum[c] << endl;
  }
  return 0;
}

 

  
  

评论区

{{item['qq_nickname']}}
()
回复
回复