answersLogoWhite

0

Let's assume that you want the sum of the general harmonic series:

sum(n=0,inf): 1/(an+b)

Since we know that the harmonic series will converge to infinity, we'll also assume that you want the sum from 0 to n.

double genHarmonic(const double n, const double a, const double b) {

double sum = 0.0;

// perform calculations

int k;

for(k = 0; k <= n; ++k) {

sum += 1.0 / (a * k + b);

}

return sum;

}

User Avatar

Wiki User

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

Class HarmonicSeries{

public static void main(String args[]){

int num = Integer.parseInt(args[0]);

double result = 0.0;

while(num > 0){

result = result + (double) 1 / num;

num--;

}

System.out.printl of Harmonic Series is "+result);

}

}

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Program to find the sum of harmonic series?
Write your answer...
Submit
Still have questions?
magnify glass
imp