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.
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;