This is a C Program to find the sum of A.P series.
This C Program calculates the sum of A.P series.
This program is used to find the sum of the arithmetic progression series. Here A.P stands for arithmetic progression. A sequence of terms each of which, after the first, is derived by adding to the preceding one a common difference: 5, 9, 13, 17, etc. forms an arithmetic progression. The formula used in thids program arel = a + (n – 1)d . where l is the last term of a finite sequence. Sn = n/2(2a + (n-1) d) where Sn is the sum of n terms.
Here is source code of the C Program to Find the the sum of A.P series. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to Find the Sum of A.P Series */ #include <stdio.h> #include <math.h> int main() { int a, d, n, i, tn; int sum = 0; printf("Enter the first term value of the A.P. series: "); scanf("%d", &a); printf("Enter the total numbers in the A.P. series: "); scanf("%d", &n); printf("Enter the common difference of A.P. series: "); scanf("%d", &d); sum = (n * (2 * a + (n - 1)* d ))/ 2; tn = a + (n - 1) * d; printf("Sum of the A.P series is: "); for (i = a; i <= tn; i = i + d ) { if (i != tn) printf("%d + ", i); else printf("%d = %d ", i, sum); } return 0; }
In this C program, we are reading the first term of the A.P. series using ‘a’ variable and the total numbers in the A.P. Series using ‘n’ variable and the common difference of the A.P. Series using ‘d’ variable.
An arithmetic progression is a sequence of terms each of which, after the first, is derived by adding to the preceding one a common difference: 5, 9, 13, 17, etc. forms an arithmetic progression. The formula used in this program is
l = a + (n – 1) d,
Where l is the last term of a finite sequence.
Sn = n/2(2a + (n-1) d),
Where, Sn is the sum of n terms.
Output: $cc pgm21.c $ a.out Enter the first term value of the A.P. series: 1 Enter the total numbers in the A.P. series: 5 Enter the common difference of A.P. series: 2 Sum of the A.P series is: 1 + 3 + 5 + 7 + 9 = 25
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy Computer Science Books
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Apply for Computer Science Internship
- Buy C Books