This question came from C++ Primer 5th edition:Q: Read a set of integers into a vector. Print the sum of each pair of  adjacent elements. Change your program so that it prints the sum of  the first and last elements, followed by the sum of the second and  second-tolast, and so on.I was just wondering if there is any way to improve my solution.Part 1:int main(){    vector<int> intVector;    int number;    while (cin >> number){        intVector.push_back(number);    }    for (int i = 0; i < intVector.size(); i++){        int k;        k = intVector[i] + intVector[i + 1];        cout << k << endl;    }    return 0;}Part 2:  int main(){    vector<int> intVector;    int number;    while (cin >> number) {        intVector.push_back(number);    }    int sizeOfIntVector = intVector.size();    for(int i = 0; i < sizeOfIntVector / 2; i++){        int k;        k = intVector[i] + intVector[sizeOfIntVector - 1 - i];        cout << k << endl;    }    return 0;}
Performing operations on a processed int vector
c++;vectors
There are few things that I want to point out.First of all, I think that this part of code has an errorfor (int i = 0; i < intVector.size(); i++){    int k;    k = intVector[i] + intVector[i + 1];    cout << k << endl;}I think it will crash when i = intVector.size() - 1 and you are trying to access intVector[i + 1]. Try looping till i < intVector.size() - 1Secondly, your second solution works fine when sizeOfIntVector is even and there is nothing to worry about. But when it is odd you are missing one sum to print. So I guess it should be something like thisint sizeOfIntVector = intVector.size();int sumsToPrintCount = sizeOfIntVector / 2;if (sizeOfIntVector % 2 == 1){    sumsToPrintCount++;}for(int i = 0; i < sumsToPrintCount; i++){    int k;    k = intVector[i] + intVector[sizeOfIntVector - 1 - i];    cout << k << endl;}