Sum of Series 1+2+3+…+n C Program

By | September 21, 2015

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

Here, we have listed How To Print The Sum of Series of Numbers in the format 1 + 2 + 3 + … + 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 + 2 + 3 + 4 + 5 = 15

Also Read: Sum of Sequence: 1 + 1/2 + 1/4 + 1/8 + …. + 1/n C Program

Method 1: Find Addition of Sequence without Function in C

#include<stdio.h>

int main()
{
    int limit, count, sum = 0;
    printf("nThe Sum of Series 1+2+3+...+n n");
    printf("Enter The Limit:t");
    scanf("%d", &limit);
    for(count = 1;count <= limit;count++)
    {
        sum = sum + count;
    }
    printf("nSum of Series:t %d", sum);
    printf("n");
    return 0;
}

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

 

Method 2: Calculate Sum of Sequence using Function in C

#include<stdio.h>

int calc_sum(int x);

int main()
{
    int limit, res;
    printf("nThe Sum of Series 1+2+3+...+n n");
    printf("Enter The Limit:t");
    scanf("%d", &limit);
    res = calc_sum(limit);
    printf("nSum of Series:t %d", res);
    printf("n");
    return 0;
}

int calc_sum(int x)
{
    int count, sum = 0;
    for(count = 1;count <= x;count++)
    {
        sum = sum + count;
    }
    return sum;
}

Output

C Program to find Sum of Series 1+2+3+..+n

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

One thought on “Sum of Series 1+2+3+…+n C Program

  1. Aditya Kothari

    Thanks. This is really amazing. I could finally solve my college assignment.

    Reply

Let's Discuss