func(int n)
// the function should return the sum of the first n term of the
// harmonic series (1/1 + 1/2 + 1/3 + ... + 1/n )
double sumover(int n)
{
if (n == 0)
return 0;
else
{
return (1. / n) + sumover(--n); // here is the bug
}
}
When the function is called with n = 1, I am expecting it to compute 1. / 1 + sumover(0) = 1 / 1 + 0
However, it's computing 1./0 + sumover(0) , why?