Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++
#include <functional>
#include <numeric>
int s = std::accumulate(x.begin(), x.end(), 0, std::plus<int>());

std::plus<int>() parameter optional (defaults to this if not provided)
#include <ranges>
auto s = std::ranges::fold_left(x, 0, std::plus<int>{});
for E of x loop
   S := S + E;
end loop;

x is an array.
S is initialized to be 0.

New implementation...
< >
deleplace