title: Sum of 1 + 1/2 + 1/3 +.... + 1/n without iterations using digamma function and Euler's constant
body: <p>So i like to make my life hard, i've got a task to calculate the sum of
  <code>1 + 1/2 + 1/3 + 1/4 +.... + 1/n</code>.
  The conditions is to not use iterations but a closed formula. On this post : <a href="https://math.stackexchange.com/questions/3367037/sum-of-1-1-2-1-3-1-n">https://math.stackexchange.com/questions/3367037/sum-of-1-1-2-1-3-1-n</a></p>
  <p>I've found a pretty neat looking solution: <code>1+1/2+1/3+⋯+1/n=γ+ψ(n+1)</code>
  where  γ is Euler's constant and ψ is the digamma function.</p>
  <p>For digamma I'm using the <a href="https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/sf_gamma/digamma.html" rel="nofollow noreferrer" title="this text appears on mouseover">boost c++ libraries</a> and I calculate the Euler's constant using exp(1.0).</p>
  <p>The problem is that I don't get the right answer. Here is my code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;boost/math/special_functions/digamma.hpp&gt;
  
  
  int main(){
  int x; 
  const double g = std::exp(1.0);
  
  std::cin &gt;&gt; x;
  
  std::cout&lt;&lt;g + boost::math::digamma(x+1);
  
  return 0;
  }
  </code></pre>
  <p>Thanks in advance) !</p>