Implement a recursive function for computing the n-th Harmonic
Implement a recursive function for computing the n-th Harmonic
number:
H
n
=∑
n
i=1
1
i
/
.
Here you have some examples of harmonic numbers.
H1 = 1
H2 = 1 + 1/2 = 1.5
H3 = 1 + 1/2 + 1/3 = 1.8333
H4 = 1 + 1/2 + 1/3 + 1/4 = 2.0833 ATTACHMENT PREVIEW Download attachment/*************************************************Week 4 lesson:**implementing a recursive factorial function **************************************************/#include <iostream>using namespace std;/** Returns the factorial of n*/long factorial(int n){if (n == 1)return 1;elsereturn n * factorial(n – 1);}int main(){int n;cout << “Enter a number: “;cin >> n;if (n > 0)cout << n << “!= ” << factorial(n) << endl;elsecout << “Input Error!” << endl;return 0;}
