fork download
  1. #include <numeric>
  2. #include <iostream>
  3.  
  4. int getTotal(const char* value, int start, int end)
  5. {
  6. return std::accumulate(value + start, value + end, 0, [](int n, char ch){ return n * 10 + (ch-'0');});
  7. }
  8.  
  9. int main()
  10. {
  11. char value[8] = {'1','2','3','4','0','0','1','4'};
  12. int total1 = getTotal(value, 0, 4);
  13. int total2 = getTotal(value, 4, 8);
  14. std::cout << total1 << " " << total2;
  15. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1234 14