在C++创建动态数组

计算首行两数相加

#include <iostream>11
#include <vector>
using namespace std;
int main()
{
	vector<int> ivec;
	int num;
	while (cin >> num)
	{
		ivec.push_back(num);
	}
	int count = ivec.size();
	for (int first = 0, last = count - 1; first <= last; first++, last--)
	{
		if (first == last)
		{
			cout << "中间数据为:" << ivec[last] << endl;
		}
		else
		cout << ivec[first] + ivec[last] << endl;
	}
	return 0;
}

  运行结果:

 


可以使用vector可以创造动态数组(如上),也可以使用

int n;
cin>>n;
int *array=new int [n];

 

posted @ 2020-02-10 15:00  菜鸟冲冲冲  阅读(2273)  评论(0)    收藏  举报