C Program to Find Sum of Arithmetic Progression Series

To find sum of arithmetic progression series in c programs; Through this tutorial, we will learn how to find sum of arithmetic progression series or AP series using for loop, while loop, and function in c programs.

Programs to Find Sum of Arithmetic Progression Series in C

  • C Program to Find Sum of Arithmetic Progression Series using For Loop
  • C Program to Find Sum of Arithmetic Progression Series using While Loop
  • C Program to Find Sum of Arithmetic Progression Series using Function

C Program to Find Sum of Arithmetic Progression Series using For Loop

/* C Program to find Sum of Arithmetic Progression Series */
#include <stdio.h>

int main() {

    int a, n, d, tn, i;
    int sum = 0;

    printf(" Please Enter First Number of an A.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this A.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Difference:  ");
    scanf("%d", &d);

    sum = (n * (2 * a + (n - 1) * d)) / 2;
    tn = a + (n - 1) * d;
    printf("\n The Sum of Series A.P. : ");
    for(i = a; i <= tn; i = i + d)
    {
        if(i != tn)
            printf("%d + ", i);
        else
            printf("%d = %d", i, sum);
    }
    printf("\n");
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an A.P Series:  1
Please Enter the Total Numbers in this A.P Series:  5
Please Enter the Common Difference:  4
The Sum of Series A.P. : 1 + 5 + 9 + 13 + 17 = 45

C Program to Find Sum of Arithmetic Progression Series using While Loop

/* C Program to find Sum of Arithmetic Progression Series */
#include <stdio.h>

int main() {

    int a, n, d, tn, i;
    int sum = 0;

    printf(" Please Enter First Number of an A.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this A.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Difference:  ");
    scanf("%d", &d);

    sum = (n * (2 * a + (n - 1) * d)) / 2;
    tn = a + (n - 1) * d;
    i = a;
    printf("\n The Sum of Series A.P. : ");
    while(i <= tn)
    {
        if(i != tn)
            printf("%d + ", i);
        else
            printf("%d = %d", i, sum);
        i = i + d;
    }
    printf("\n");
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an A.P Series:  1
Please Enter the Total Numbers in this A.P Series:  6
Please Enter the Common Difference:  5
The Sum of Series A.P. : 1 + 6 + 11 + 16 + 21 + 26 = 81

C Program to Find Sum of Arithmetic Progression Series using Function

/* C Program to find Sum of Arithmetic Progression Series */
#include <stdio.h>
int sumofAP(int a, int n, int d)
{
    int sum = (n * (2 * a + (n - 1) * d)) / 2;
    return sum;
}
int main() {

    int a, n, d;
    int sum = 0;

    printf(" Please Enter First Number of an A.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this A.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Difference:  ");
    scanf("%d", &d);

    sum = sumofAP(a, n, d);

    printf("\n The Sum of Arithmetic Progression Series is =  %d\n", sum);
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an A.P Series:  1
Please Enter the Total Numbers in this A.P Series:  8
Please Enter the Common Difference:  6
The Sum of Arithmetic Progression Series is =  176

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *