answersLogoWhite

0


Best Answer

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

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

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);

}

}

This answer is:
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
Related questions

Write a program to find the sum of sine series?

Writing a program for a sum of sine series requires a rather long formula. That formula is: #include #include #include main() { int i,n,x; .


What is the assembly program to generate a geometric series and compute its sum The inputs are the base root and the length of the series The outputs are the series elements and their sum?

What is the assembly program to generate a geometric series and compute its sum The inputs are the base root and the length of the series The outputs are the series elements and their sum?


How do you find the sum of nos in a series?

It depends on the series.


What is 1 plus 1 half plus 1 third plus 1 quarter plus 1 fifth and so on?

This series is known as the Harmonic Series and it diverges but very, very slowly. For example, the first 100 terms sum to 5.187...., the first 1000 terms to 7.486...., and the first 1000000 terms to 14.392.... There are many proofs of the divergence of this series and an internet search of Harmonic Series will no doubt find many of them.


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


Write a program to find the sum of all positive number and terminate the program when sum exceed 999?

int sum = 0; int n = 0; while( sum &lt;= 999 ) { sum += (++n); }


Writes a c program to find the sum of all integers between 1 and n?

Write a program to find the number and sum of all integers from 100 to 300 that are divisible by 11


Java program to find sum on even numbers from 12-45?

sum = 0; for (int i = 12; i


How can you find the nth partial?

The Nth partial sum is the sum of the first n terms in an infinite series.


Write a C program to find sum of 3 matrices?

matrix


To find LCM of n numbers using 8085 programs?

sample program in sum of the series using the formula for s=n/2[2a+{n-1}d] in 8085


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.