C Program to Find Sum of Arithmetic Progression Series

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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