hi, I dont understant the red line of this code : int fac_1(int num) { int *arra
ID: 3609990 • Letter: H
Question
hi, I dont understant the red line of this code : int fac_1(int num) {int *array = newint[num];
for (int i = 0; i <num; i++)
array[i] = i+1;
intresult = std :: accumulate(array, array+num, 1,std::multiplies<int>());
delete [] array;
return result;
} can someone please explain it ? ? please if its possiple rewrite the codes in a simpler way . .. hi, I dont understant the red line of this code : int fac_1(int num) {
int *array = newint[num];
for (int i = 0; i <num; i++)
array[i] = i+1;
intresult = std :: accumulate(array, array+num, 1,std::multiplies<int>());
delete [] array;
return result;
} can someone please explain it ? ? please if its possiple rewrite the codes in a simpler way . .. can someone please explain it ? ? please if its possiple rewrite the codes in a simpler way . ..
Explanation / Answer
The functionobject binary_op is not required to be eithercommutative or associative: the order of all ofaccumulate's operations is specified. The result is firstinitialized to init. Then, for each iterator i in[first, last), in order from beginning to end, it isupdated by result = result + *i (in the first version) orresult = binary_op(result, *i) (in the secondversion).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.