Recursion Help

closed account (G3AqfSEw)
Define a recursive function int sum_range(int low, int high) that computes the sum
low+(low+1)+(low+2)+⋯+high
using recursion. You can assume low≤high.

1
2
3
4
5
6
7
int sum_range (int low, int high)
{
   if (low == high)
      return 1;
   else
   ???
}
1
2
3
4
5
6
7
8
9
10
# include <cassert>
int sum_range(int low, int high) {
  assert(low <= high);
  return low == high? low: low + sum_range(low + 1, high);
}

int main() { 
  assert(sum_range(0, 10) == 55);
  assert(sum_range(5, 10) == 45);
}

Live demo:
http://coliru.stacked-crooked.com/a/9e2024898e3dd9b3
closed account (G3AqfSEw)
This is all I'm given:

int sum_range(int low, int high)
{


}

I have to fill the space in.
Topic archived. No new replies allowed.