12

Is there any formula for this series "1 + 1/2 + 1/3 + --- + 1/n = ?" I think it is a harmonic number in a form of sum(1/k) for k = 1 to n.

Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
user451587
  • 385
  • 2
  • 8
  • 21
  • 10
    This belongs on e.g. http://math.stackexchange.com/ – You Sep 20 '10 at 01:30
  • 1
    Not really - not advanced enough. – duffymo Sep 20 '10 at 01:32
  • 2
    Well, it's not programming related – it's math related. – You Sep 20 '10 at 01:35
  • 8
    @duffymo: Actually, math.stackexchange.com sounds like a perfect home for this question -- it's explicitly for "math at any level", unlike, say, mathoverflow.net. – Jim Lewis Sep 20 '10 at 01:46
  • Thanks guys! I will visit that site. The answer of this question will help me solve a prob in Algorithm, which is computer-related though – user451587 Sep 20 '10 at 02:11
  • @Jim Lewis - Thanks for the heads up. I didn't realize that there were two math URLs now. – duffymo Sep 20 '10 at 14:43
  • Integrate 1/x from 1 to n. Therefore it gives [ ln(x) + c ] as the answer. – Rahul Dec 02 '12 at 18:42
  • 3
    Why not move it instead of closing it? Search engines still link to these closed questions and it's generally unproductive and unwelcoming to new users to treat them like this. – Xonatron Jan 07 '14 at 19:04

4 Answers4

10

As it is the harmonic series summed up to n, you're looking for the nth harmonic number, approximately given by γ + ln[n], where γ is the Euler-Mascheroni constant.

For small n, just calculate the sum directly:

double H = 0;
for(double i = 1; i < (n+1); i++) H += 1/i;
You
  • 22,800
  • 3
  • 51
  • 64
3

If I understood you question correctly, reading this should help you: http://en.wikipedia.org/wiki/Harmonic_number

dee-see
  • 23,668
  • 5
  • 58
  • 91
2

Here's one way to look at it:

http://www.wolframalpha.com/input/?i=sum+1/j,+j%3D1+to+n

duffymo
  • 305,152
  • 44
  • 369
  • 561
0
function do(int n) 
{
    if(n==1)
        return n;

    return 1/n + do(--n); 
}
bevacqua
  • 47,502
  • 56
  • 171
  • 285