accumulate & iota (<numeric>)
Në shqip: Algoritmet numerike
ShpjegimiSQ
Libraria <numeric> ka algoritme për numra: accumulate() i mbledh të gjitha elementet (ose i kombinon sipas dëshirës), iota() e mbush një varg me numra radhazi 1, 2, 3…, dhe partial_sum() jep shumat e pjesshme.
EnglishEN
The <numeric> library has algorithms for numbers: accumulate() adds up all the items (or combines them however you like), iota() fills an array with consecutive numbers 1, 2, 3…, and partial_sum() gives running totals.
Si ta mendosh
Si arkëtari që i mbledh të gjitha çmimet në shportë me një shtypje butoni.
Lexoje në anglisht
Like a cashier totalling everything in the basket with one press of a button.
Shembull kodicpp
#include <numeric>
std::vector<int> v(5);
std::iota(v.begin(), v.end(), 1); // 1 2 3 4 5
int shuma = std::accumulate(v.begin(), v.end(), 0); // 15