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.

advertisement
advertisement

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.

Note: Join free Sanfoundry classes at Telegram or Youtube

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.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.