Recursive Function

Status
Not open for further replies.

emmcee

New Member
Joined
Sep 9, 2011
Messages
29
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(n)
If n > 0 Then
harmonicRecurs = harmonicRecurs + 1 / n
Else
harmonicRecurs = 1
End If
End Function

Can anybody help? please. thank you!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Status
Not open for further replies.

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top