# C program to Find the Sum of Harmonic Progression Series

«
»

This is a C Program to find the sum of H.P series.

Problem Description

This C Program calculates the sum of H.P series.

Problem Solution

This program is used to find the sum of the harmonic progression series. Here H.P stands for harmonic progression. Harmonic progression is a progression formed by taking the reciprocals of an arithmetic progression.

Program/Source Code

Here is source code of the C Program to Find the the sum of H.P series. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

```/*
* C Program to Find the Sum of H.P Series
*/
#include <stdio.h>

void main()
{
int n;
float i, sum, term;

printf("1 + 1 / 2 + 1 / 3 +......+1 / n \n");
printf("Enter the value of n \n");
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; i++)
{
term = 1 / i;
sum = sum + term;
}
printf("the Sum of H.P Series is = %f", sum);
}```
Program Explanation

In this C program, we are reading the limit to compute the harmonic progression from the series 1 + 1 / 2 + 1 / 3 +……+1 / n using ‘n’ integer variable. Harmonic progression is a progression formed by taking the reciprocals of an arithmetic progression.

Note: Join free Sanfoundry classes at Telegram or Youtube

For loop is used to perform the addition for each integer values in the harmonic series up to the limit as mentioned by user in ‘n’ variable. Print the sum of H.P series using printf statement.

Runtime Test Cases
```
Output:
\$ cc pgm23.c
\$ a.out
1 + 1 / 2 + 1 / 3 +......+1 / n
Enter the value of n
5
the Sum of H.P Series is = 2.283334```

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Take C Programming Mock Tests - Chapterwise!
Start the Test Now: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples. 