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.
Asked
Active
Viewed 7.9k times
12
-
10This belongs on e.g. http://math.stackexchange.com/ – You Sep 20 '10 at 01:30
-
1Not really - not advanced enough. – duffymo Sep 20 '10 at 01:32
-
2Well, 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
-
3Why 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 Answers
10
As it is the harmonic series summed up to n
, you're looking for the n
th 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
0
function do(int n)
{
if(n==1)
return n;
return 1/n + do(--n);
}

bevacqua
- 47,502
- 56
- 171
- 285
-
3
-
3If the number is large enough you will get a stack overflow, or you will be adding basically zero, and not really changing the value much. – James Black Sep 20 '10 at 01:38
-