First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

Write a program to calculate the value of series:1+1/2+1/3.......+1/n

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
#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);
}
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
...