hello
I'm trying to find the harmonic number of a range of values lets say from 1 - 100 and to work out harmonic number it is the sum of the first n reciprocals (n is a positive integer, and the reciprocal of k is 1/k).
For example: For 3 it is (1/1 + 1/2 + 1/3) = 1 + 0.5 + 0.333333… = 1.833333…
I wrote this code for it but i don't know how to add the previous answers and write it in code form :
Option Explicit
Dim n As Double
Function harmonicRecurs
If n > 0 Then
harmonicRecurs = harmonicRecurs + 1 / n
Else
harmonicRecurs = 1
End If
End Function
Can anybody help? please. thank you!
I'm trying to find the harmonic number of a range of values lets say from 1 - 100 and to work out harmonic number it is the sum of the first n reciprocals (n is a positive integer, and the reciprocal of k is 1/k).
For example: For 3 it is (1/1 + 1/2 + 1/3) = 1 + 0.5 + 0.333333… = 1.833333…
I wrote this code for it but i don't know how to add the previous answers and write it in code form :
Option Explicit
Dim n As Double
Function harmonicRecurs
If n > 0 Then
harmonicRecurs = harmonicRecurs + 1 / n
Else
harmonicRecurs = 1
End If
End Function
Can anybody help? please. thank you!