Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

Use pseudocode to create a recursive algorithm to compute the n-th value of the harmonic series for some integer n

OpenStudy (anonymous):

harmonic series: \(\huge \Sigma_{i=1}^{\infty}\dfrac{1}{i} =1+\dfrac{1}{2}+\dfrac{1}{3}+...\) what do you have so far?

OpenStudy (mathmate):

Welcome to OS! Please read CoC and T&C, links of which are at the bottom left of the page. @♂ has already provided the definition of the series. You just have to crank out the algorithm in pseudocode, or in Python if you're more familiar with it. If you encounter problems, post what you have and we can take it from there. Good luck!

OpenStudy (anonymous):

they messaged me some code ``` n = input("Enter n:") def harmonicRange (sum,n): sum += 1/n n- - 1 if n < 1: return harmonicRange(sum,n) else: print sum ```

OpenStudy (mathmate):

Assuming code is from op. Usually printing is done in the calling program. It would be a good practice to initialize sum to zero before summing. ``` n = input("Enter n:") # call function here with argument n only # print results here def harmonicRange (sum,n): # function definition should precede main program # initialize value of sum to zero here # make a for/while loop from k=n to 1 sum += 1/n # add 1/k, use the loop variable k n- - 1 # wrong syntax if n < 1: return harmonicRange(sum,n) # return value of sum else: print sum # print not required if printed in calling function ``` Here are some comments on the code. See if you can correct and compile. As a check, n=10 should return 2.928968... If you get stuck, post what you have and what the message says, or what is not right.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!