fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::vector<int> vec{1,4,2,6,9,10,17,13,15};
  8. auto last_it = vec.crbegin();
  9.  
  10. for(int first : vec)
  11. {
  12. int first_last = first + *last_it++;
  13. std::cout << "Add First and Last Digit : " << first_last << std::endl;
  14. }
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5400KB
stdin
Standard input is empty
stdout
Add First and Last Digit : 16
Add First and Last Digit : 17
Add First and Last Digit : 19
Add First and Last Digit : 16
Add First and Last Digit : 18
Add First and Last Digit : 16
Add First and Last Digit : 19
Add First and Last Digit : 17
Add First and Last Digit : 16