Write a recursive method called sumover that has one argumen

Write a recursive method called sumover that has one argument n, which is a non-negative integer. The method returns a double value, which is the sum of the reciprocals of the first n positive integers. (The reciprocal of x is the fraction 1/x.) For example, sumover(1) returns 1.0 (which is 1/1); sumover(2) returns 1.5 (which is 1/1 + 1/2); and sumover(3) returns approximately 1.833 (which is 1/1 + 1/2 + 1/3). Define sumover(0) to be zero. Do not use any local variables in your method.

Solution

double sumover(int n)

{

if(n==0)return 0.0;

if(n==1)return 1.0;

if(n>1)return (1/n)+sumover(n-1);

}

 Write a recursive method called sumover that has one argument n, which is a non-negative integer. The method returns a double value, which is the sum of the re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site