Logo

Programming-Idioms

History of Idiom 54 > diff from v42 to v43

Edit summary for version 43 by programming-idioms.org:
Restored version 41: OT

Version 42

2020-11-20, 22:20:48

Version 43

2020-11-21, 14:46:36

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Variables
s,x
Variables
s,x
Imports
#include <functional>
#include <numeric>
Imports
#include <functional>
#include <numeric>
Code
for(i = 0; i<=b; i++){
   s= s + (1/(x+(i*y)));
}
Code
int s = std::accumulate(x.begin(), x.end(), 0, std::plus<int>());