C++ primer P94 练习3.20

来源:互联网 发布:贵阳大数据产业博览会 编辑:程序博客网 时间:2024/06/06 03:30
#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;} 


0 0