int sum(int a, int b)
{
  if(a > b) return 0;
  else return a + sum(a+1, b);
}

 

Thought process.

If a > b, then there are no numbers that are greater than or equal to a and less than or equal to b. The sum of no numbers is 0.

If a <= b, then

sum(a,b) = a + (a+1) + ... + b
  = a + sum(a+1, b)