- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to find the sum of arithmetic progression series
Problem
Find the sum of an arithmetic progression series, where the user has to enter first number, total number of elements and the common difference.
Solution
Arithmetic Progression (A.P.) is a series of numbers in which the difference of any two consecutive numbers is always the same. Here, total number of elements is mentioned as Tn.
Sum of A.P. Series: Sn = n/2(2a + (n – 1) d) Tn term of A.P. Series: Tn = a + (n – 1) d
Algorithm
Refer an algorithm given below to find the arithmetic progression.
Step 1: Declare variables. Step 2: Initialize sum=0 Step 3: Enter first number of series at runtime. Step 4: Enter total number of series at runtime. Step 5: Enter the common difference at runtime. Step 6: Compute sum by using the formula given below. sum = (num * (2 * a + (num - 1) * diff)) / 2 Step 7: Compute tn by using the formula given below. tn = a + (num - 1) * diff Step 8: For loop i = a; i <= tn; i = i + diff i. if(i != tn) printf("%d + ", i); ii. Else, printf("%d = %d", i, sum); Step 9: Print new line
Program
Following is the C Program to find the sum of arithmetic progression series−
#include <stdio.h> int main() { int a, num, diff, tn, i; int sum = 0; printf(" enter 1st no of series: "); scanf("%d", &a); printf(" enter total no's in series: "); scanf("%d", &num); printf("enter Common Difference: "); scanf("%d", &diff); sum = (num * (2 * a + (num - 1) * diff)) / 2; tn = a + (num - 1) * diff; printf("
sum of A.P series is : "); for(i = a; i <= tn; i = i + diff){ if(i != tn) printf("%d + ", i); else printf("%d = %d", i, sum); } printf("
"); return 0; }
Output
When the above program is executed, it produces the following result −
enter 1st no of series: 3 enter total no's in series: 10 enter Common Difference: 5 sum of A.P series is: 3 + 8 + 13 + 18 + 23 + 28 + 33 + 38 + 43 + 48 = 255 enter 1st no of series: 2 enter total no's in series: 15 enter Common Difference: 10 sum of A.P series is: 2 + 12 + 22 + 32 + 42 + 52 + 62 + 72 + 82 + 92 + 102 + 112 + 122 + 132 + 142 = 1080
- Related Articles
- C Program for N-th term of Arithmetic Progression series
- C++ Program for sum of arithmetic series
- JavaScript code to find nth term of a series - Arithmetic Progression (AP)
- Find the missing number in Arithmetic Progression in C++
- Program to find sum of harmonic series in C++
- C Program for N-th term of Geometric Progression series
- Missing Number In Arithmetic Progression using C++
- What is arithmetic progression?
- 8085 program to find the sum of a series
- Python program to find the sum of sine series
- The sum of $3^{rd}$ and $15^{th}$ elements of an arithmetic progression is equal to the sum of $6^{th}$, $11^{th}$ and $13^{th}$ elements of the same progression. Then which elements of the series should necessarily be equal to zero?
- In an arithmetic progression, if the $k^{th}$ term is $5k+1$, then find the sum of first $100$ terms.
- Program to check we can make arithmetic progression from sequence in Python
- 8085 program to find the sum of series of even numbers
- If eight times the $8^{th}$ term of an arithmetic progression is equal to seventeen times the $7^{th}$ term of the progression, find the $15^{th}$ term of the progression.

Advertisements