C Exercises: Calculate the harmonic series and their sum
19. Harmonic Series and Their Sum
Write a program in C to display the n terms of a harmonic series and their sum.
The series is : 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n terms
This C program displays the first n terms of a harmonic series and calculates their sum. The harmonic series is represented as 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n. The program will prompt the user to input the value of n, then use a loop to compute and display each term, as well as the cumulative sum of the series.
Visual Presentation:

Sample Solution:
C Code:
Output:
Input the number of terms : 5 1/1 + 1/2 + 1/3 + 1/4 + 1/5 Sum of Series upto 5 terms : 2.283334
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to display the first n terms of the harmonic series and then compute their product.
- Write a C program to calculate the harmonic series recursively and display the running total at each step.
- Write a C program to output the harmonic series and then compute the average of the terms.
- Write a C program to display the harmonic series with formatted output and calculate its sum to a given precision.
C Programming Code Editor:
Previous: Write a program in C to find the sum of the series [ 1-X^2/2!+X^4/4!- .........].
Next: Write a program in C to display the pattern like a pyramid using asterisk and each row contain an odd number of asterisks.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.