计算首行两数相加
#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];