Try the fastest way to create flashcards
Question

# Write the following function. The call sum(g, 1, j) should returng(i) + ... +g (j).int sum(int (*f)(int), int start, int end); 

Solution

Verified
Step 1
1 of 2

A function that sums the return values of the passed function given a range of values:

int sum(int (*f)(int), int start, int end)
{
int sum = 0;
while (start <= end) {

// call the passed function
// passing the values between
// start and end
sum += (*f)(start);
start++;
}

return sum;
}


## Recommended textbook solutions #### Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions #### Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions #### Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions #### C Programming: A Modern Approach

2nd EditionISBN: 9780393979503K N King
495 solutions