c program harmonic series and their sum


    Write a c program to display the n terms of harmonic series and their sum.

    The following code is used to generate the harmonic numbers and their sum

    What are harmonic numbers?

    Harmonic series is a series which increase and divide the 1 by n term start from 1 to n
    1, 1/2, 1/3, 1/4, 15 .... 1/n

    This series will be used in music composition of tunes
    
    /*
    Author: Rupesh Darimisetti
    Purpose: Write a c program to display the n terms of harmonic series and their sum.
    */
    
    #include<stdio.h>
    // #include<conio.h>
    
    void main(){
        int n;
        float harmonic_sum=0.0;
    
        printf("Enter a numbr to display and print the sum of n harmonic numbers:\t");
        scanf("%d",&n);
        // Display harmonic series in line and adds the sum
        printf("The harmonic numbers:\n");
        for(int pos=1;pos<=n;pos++){
            printf("1/%d\n",pos);
            harmonic_sum+=(1.0f/pos);
        }
    
        printf("The sum of %d harmonic numbers is \t%f",n,harmonic_sum);
        //getch();
    }