Click here to Skip to main content
15,887,880 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
The goal of Part 2 is to develop an algorithm and implement code to calculate the series sum of reciprocals S(n) = (1/1 + 1/2 + 1/3 + 1/4 + … + 1/n) such that your program finds the smallest number n for which the series sum of reciprocals S(n) EQUALS OR EXCEEDS a value entered by the user.

For example, if the user enters 1.5 your program should display the following:

The smallest series sum >= 1.5 is S(2) which has the value 1.5.

What I have tried:

I have tried everything I know and can't seem to get the output to be correct.
Posted
Updated 11-Feb-18 17:43pm
Comments
[no name] 11-Feb-18 22:09pm    
Show us your code. Don't be shy.

1 solution

The harmonic series has a lot of roundoff error for large N. Does your program work for N = 10?
For N = 1,000,000 S = 14.393, and the difference between adjacent terms may be less than roundoff.
Use compensated addition Kahan summation algorithm - Wikipedia[^]
and store each term in an array S[]. Then binary search the array for the target value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900