#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
vector<int> vec;
int num;
cout << "please input the numbers:" << endl;
while (cin >> num){
vec.push_back(num);
}
int length = vec.size();
if (length == 0){
cout << "there is no number!" << endl;
return 0;
}
for (int j = 0; j < length - 1; j += 2){
cout << vec[j] + vec[j + 1] << " ";
}
cout << endl;
if (length % 2 != 0){
cout << "the last number " << vec[length - 1]<<" can't be added to other" << endl;
}
for (int j = 0; j < length / 2;j++){
cout << vec[j] + vec[length - 1 - j] << " ";
}
cout << endl;
if (length % 2 != 0){
cout << "the mid number " << vec[length / 2] << " can't be added to other" << endl;
}
cout << endl;
return 0;
}
C++ primer P94 练习3.20
最新推荐文章于 2021-10-11 00:07:35 发布