C program to find the sum of Series:



Coding in C:

#include<stdio.h>
#include<conio.h>
int main()
{
    float number, sum = 0, i;

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


Output:


 enter the number: 5

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

2 comments:

  1. Can you give me the output of the program

    ReplyDelete
    Replies

    1. enter the number: 5

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

      Delete