The problem with the above code is that both 1 and i are integers, so when you do result = result + 1/i, it will return zero for all (1/i), i > 1. As a result, you will have 1 + 0 + 0 + ... + 0 = 1.

Also, the loop could be shortened to

i = 1;

while(i < (10^n))

result += (1/i++);

However, I don't understand your motivation for doing such a thing. If it's understanding how to program a loop, I suggest you find a better example.

The series (summation of 1/i, i = 0 to 10^n) can be thought of as the Riemann sum for 1/x, and it turns out that is how we define the natural logarithm. ln(x) = int(du/u) from 1 to x. You may use ln(x) to under-approximation sum(x=1 to 10^n, 1/x). In this case ln(10^n) = n*ln(10), which is much faster than a loop which iterates 10^n times.

The difference between the two functions as you head towards infinity is

The Euler-Mascheroni constant, gamma.