In this tutorial you will learn about the C Program to Find Sum of Arithmetic Progression Series and its application with practical example.
C Program to Find Sum of Arithmetic Progression Series
In this tutorial, we will learn to create a C program that will Find Sum of Arithmetic Progression Series using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C Programming.
- Functions in C Programming.
What is Arithmetic Progression?
The arithmetic progression is a series in mathematics that starts from a point and the second term is having a common difference, and this series continues till the endpoint with the common difference.
Programs to Find Sum of Arithmetic Progression Series:-
In this program, First, we take the first term of the arithmetic progression. Then we will take the total number of terms in A.P. At last we will take the common difference from the user. Now we will generate the arithmetic progression using the for loop and the mathematical expressions. Then will print the sum of the arithmetic progression.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* C Program to find Sum of Arithmetic Progression Series */ #include <stdio.h> int main() { //DEclaring the required variables for the program. int first_term, no, dis, tn, i; int sum = 0; //Taking the first term of A.P. printf(" Please Enter First Number of an A.P Series: "); scanf("%d", &first_term); //Taking the number of terms in ap printf(" Please Enter the Total Numbers in this A.P Series: "); scanf("%d", &no); //Taking the Common Difference of ap printf(" Please Enter the Common Difference: "); scanf("%d", &dis); //Creating the Arithmetic Progression. sum = (no * (2 * first_term + (no - 1) * dis)) / 2; tn = first_term + (no - 1) * dis; //Calculating the sum of a.p. printf("\n The Sum of Series A.P. : "); for(i = first_term; i <= tn; i = i + dis) { if(i != tn) printf("%d + ", i); else printf("%d = %d", i, sum); } printf("\n"); return 0; } |
Output:-
In the above program, we have first initialized the required variable
- first_term = it will hold the integer value.
- no = it will hold the integer value.
- dis = it will hold the integer value.
- tn = it will hold the integer value.
- i = it will hold the integer value to control the array.
Taking the first term, common distance, and the number of terms from the user.
Generating the A.P. using the loops and calculating the sum.
Program Code for Printing the sum of series.