Sum of Series 1+1/2+1/4+1/8+…+1/n C Program

By | October 17, 2015

C Program To Print Sum of Series 1+1/2+1/4+1/8+…+1/n

Here, we have listed How To Print The Sum of Series of Numbers in the format 1 + 1/2 + 1/4 + 1/8 + … +1/n in C Programming Language. It is important that we should know about the How A For Loop Works before getting further with the C Program Code.

We have listed following Methods to Find The Sum of Sequence in C Programming:

  • Addition of Series without Function
  • Sum of Sequence with Function

In this C Program, we take a Limit as an Input from the user. Suppose, if the user enters the Limit as 5, the program will calculate the Sum of Series starting from Number 1 to 5.

Example

1 + 1/2 + 1/4 + 1/8 + 1/16 = 1.9375

Also Read: Addition of Series 1 + 2 + 3 + 4 + …. + N C Program

Method 1: Find Addition of Series without using Function in C

#include<stdio.h>
 
int main()
{
    float sum = 0.0, j = 1.0;
    int count, limit;
    printf("\nThe Sum of Series 1+1/2+1/4+1/8...+1/n \n");
    printf("Enter The Limit:\t");
    scanf("%d", &limit);
    for(count = 1; count <= limit; count++)
    {
        sum = sum + (1/j);
        j = j * 2;
    }
    printf("\nSum of Series:\t %f", sum);
    printf("\n");
    return 0;
}

Also Read: Addition of Series 1 + 1/2 + 1/3 + 1/4 + …. + 1/n C Program

 

Method 2: Calculate Addition of Series using Function in C

#include<stdio.h>

float sum_cal(int limit);

int main()
{
    float res;
    int limit;
    printf("\nThe Sum of Series 1+1/2+1/4+1/8...+1/n \n");
    printf("Enter The Limit:\t");
    scanf("%d", &limit);
    res = sum_cal(limit);
    printf("\nSum of Series:\t %f", res);
    printf("\n");
    return 0;
}

float sum_cal(int limit)
{
    float sum = 0.0, j = 1.0;
    int count;
    for(count = 1; count <= limit; count++)
    {
        sum = sum + (1/j);
        j = j * 2;
    }
    return sum;
}

Output

C Program To Print Sum of Series 1+1/2+1/4+1/8+1/n

If you have any compilation errors or doubts in this C Program for Addition of Series, let us know about it in the Comment Section below.

4 thoughts on “Sum of Series 1+1/2+1/4+1/8+…+1/n C Program

    1. Tushar Soni Post author

      Thanks Mahesh. Here, at CodingAlpha we focus on providing perfectly working and executable programs to students.

      Reply
  1. Pooja mehta

    I really dont understand these pattern codes for finding sum of series in C programming. I only need it for mh college assignments. 🙂

    Reply
  2. Pavan Kumar

    Can I know how to add the series of
    1+(1+2)+(1+2+3)+….+(1+2+….+n)

    Reply

Let's Discuss