Given a number N. The task is to find the Nth Harmonic Number.
Let the nth harmonic number be Hn.
The harmonic series is as follows:
H1 = 1
H2 = H1 + 1/2
H3 = H2 + 1/3
H4 = H3 + 1/4
Hn = Hn-1 + 1/n
Input : N = 5 Output : 2.45 Input : N = 9 Output : 2.71786
The idea is to traverse from H1 and then consecutively keep finding H2 from H1, H3 from H2 ….. and so on.
Below is the program to find N-th Harmonic Number:
Time Complexity: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to find sum of harmonic series
- Program for harmonic mean of numbers
- Find Harmonic mean using Arithmetic mean and Geometric mean
- Harmonic progression Sum
- Leibniz harmonic triangle
- Harmonic Progression
- Summation of floor of harmonic progression
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Program to find last two digits of Nth Fibonacci number
- Program to find the nth Kynea number
- Program to find the Nth number of the series 2, 10, 24, 44, 70.....
- Program to find the Nth Prime Number
- Program to find Nth odd Fibonacci Number
- Find Nth number in a sequence which is not a multiple of a given number
- Program to find Nth term in the given Series
- Program to find the Nth term of the series 3, 7, 13, 21, 31.....
- Program to find Nth term of series 1, 3, 12, 60, 360…
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- Program to find Nth term in the series 0, 0, 2, 1, 4, 2, 6, 3, 8,...
- Program to find Nth term of series 9, 23, 45, 75, 113...
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.