This is a C Program to find the sum of H.P series.
This C Program calculates the sum of H.P series.
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.
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); }
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.
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.
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.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Apply for C Internship
- Apply for Computer Science Internship
- Practice BCA MCQs