I have been making various functions that will compute the sigma in a range of very specific functions. I am now trying to write a sigma function that you would input a lambda or a function and it would then calculate the sum of its outputs within a range. I have the iteration code done fine but now need to figure out how to input a lambda and call it inside that function. here is my current code:
int sigma(int start, int end, ? function) {
if (start == end) {
return function(start);
}
else {
return function(start) + sigma(start + 1, end, function);
}
}
PS if anyone could help me make this not use recursion that would be amazing