Thursday, 16 November 2017

C Program to find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + … + 1/N


Code:

#include   stdio.h

void main()
{
    double number, sum = 0, i;

    printf("\n enter the number ");
    scanf("%lf", &number);
    for (i = 1; i <= number; i++)
    {
        sum = sum + (1 / i);
        if (i == 1)
            printf("\n 1 +");
        else if (i == number)
            printf(" (1 / %lf)", i);
        else
            printf(" (1 / %lf) + ", i);
    }
    printf("\n The sum of the given series is %.2lf", sum);
}

Output:

enter the number 4

1 + (1/2.000000) +  (1/3.000000) +  (1/4.000000)
The sum of the given series is 2.08


More C Programs:














100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...