A sequence of numbers is called an Arithmetic progression if the difference between any two consecutive terms is always the same. In simple terms, it means that the next number in the series is calculated by adding a fixed number to the previous number in the series. For example, 2, 4, 6, 8, 10 is an AP because difference between any two consecutive terms in the series (common difference) is same (4 – 2 = 6 – 4 = 8 – 6 = 10 – 8 = 2).

Fact about Arithmetic Progression :
- Initial term: In an arithmetic progression, the first number in the series is called the initial term.
- Common difference: The value by which consecutive terms increase or decrease is called the common difference.
- The behavior of the arithmetic progression depends on the common difference d. If the common difference is:positive, then the members (terms) will grow towards positive infinity or negative, then the members (terms) will grow towards negative infinity.
Formula of nth term of an A.P :
If ‘a’ is the initial term and ‘d’ is the common difference.Thus, the explicit formula is

Formula of sum of nth term of A.P:

How we check whether a series is arithmetic progression or not?
- Naive solution.
The idea is to sort the given array or series. After sorting, check if differences between consecutive elements are same or not. If all differences are same, Arithmetic Progression is possible.
Below is the implementation of this approach:
C++
// C++ program to check if a given array// can form arithmetic progression#include <bits/stdc++.h>usingnamespacestd;// Returns true if a permutation of arr[0..n-1]// can form arithmetic progressionboolcheckIsAP(intarr[],intn){if(n == 1)returntrue;// Sort arraysort(arr, arr + n);// After sorting, difference between// consecutive elements must be same.intd = arr[1] - arr[0];for(inti = 2; i < n; i++)if(arr[i] - arr[i - 1] != d)returnfalse;returntrue;}// Driven Programintmain(){intarr[] = { 20, 15, 5, 0, 10 };intn =sizeof(arr) /sizeof(arr[0]);(checkIsAP(arr, n)) ? (cout <<"Yes"<< endl) : (cout <<"No"<< endl);return0;}chevron_rightfilter_noneJava
// Java program to check if a given array// can form arithmetic progressionimportjava.util.Arrays;classGFG {// Returns true if a permutation of// arr[0..n-1] can form arithmetic// progressionstaticbooleancheckIsAP(intarr[],intn){if(n ==1)returntrue;// Sort arrayArrays.sort(arr);// After sorting, difference between// consecutive elements must be same.intd = arr[1] - arr[0];for(inti =2; i < n; i++)if(arr[i] - arr[i -1] != d)returnfalse;returntrue;}// driver codepublicstaticvoidmain(String[] args){intarr[] = {20,15,5,0,10};intn = arr.length;if(checkIsAP(arr, n))System.out.println("Yes");elseSystem.out.println("No");}}// This code is contributed by Anant Agarwal.chevron_rightfilter_nonePython3
# Python3 program to check if a given# array can form arithmetic progression# Returns true if a permutation of arr[0..n-1]# can form arithmetic progressiondefcheckIsAP(arr, n):if(n==1):returnTrue# Sort arrayarr.sort()# After sorting, difference between# consecutive elements must be same.d=arr[1]-arr[0]foriinrange(2, n):if(arr[i]-arr[i-1] !=d):returnFalsereturnTrue# Driver codearr=[20,15,5,0,10]n=len(arr)print("Yes")if(checkIsAP(arr, n))elseprint("No")# This code is contributed by Anant Agarwal.chevron_rightfilter_noneC#
// C# program to check if a given array// can form arithmetic progressionusingSystem;classGFG {// Returns true if a permutation of// arr[0..n-1] can form arithmetic// progressionstaticboolcheckIsAP(int[] arr,intn){if(n == 1)returntrue;// Sort arrayArray.Sort(arr);// After sorting, difference between// consecutive elements must be same.intd = arr[1] - arr[0];for(inti = 2; i < n; i++)if(arr[i] - arr[i - 1] != d)returnfalse;returntrue;}// Driver CodepublicstaticvoidMain(){int[] arr = { 20, 15, 5, 0, 10 };intn = arr.Length;if(checkIsAP(arr, n))Console.WriteLine("Yes");elseConsole.WriteLine("No");}}// This code is contributed by vt_m.chevron_rightfilter_nonePHP
<?php// PHP program to check if// a given array can form// arithmetic progression// Returns true if a permutation// of arr[0..n-1] can form// arithmetic progressionfunctioncheckIsAP($arr,$n){if($n== 1)returntrue;// Sort arraysort($arr);// After sorting, difference// between consecutive elements// must be same.$d=$arr[1] -$arr[0];for($i= 2;$i<$n;$i++)if($arr[$i] -$arr[$i- 1] !=$d)returnfalse;returntrue;}// Driver Code$arr=array(20, 15, 5, 0, 10);$n=count($arr);if(checkIsAP($arr,$n))echo"Yes";elseecho"No";// This code is contributed// by Sam007?>chevron_rightfilter_none
Output:Yes
Time Complexity: O(n Log n).
- Efficient solutions
Basic Program related to Arithmetic Progression
- Program for sum of arithmetic series
- Program to print Arithmetic Progression series
- Longest arithmetic progression with the given common difference
- Check whether Arithmetic Progression can be formed from the given array
- Find the missing number in Arithmetic Progression
- Find N Arithmetic Means between A and B
- Sum of the numbers upto N that are divisible by 2 or 5
- Find First element in AP which is multiple of given prime
More problems related to Arithmetic Progression
- Sum of first n terms of a given series 3, 6, 11, …..
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Probability for three randomly chosen numbers to be in AP
- Print all triplets in sorted array that form AP
- Program for N-th term of Arithmetic Progression series
- Sum of Arithmetic Geometric Sequence
- Count of AP (Arithmetic Progression) Subsequences in an array
Recent Articles on Arithmetic Progression!
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Longest Arithmetic Progression | DP-35
- Find the missing number in Arithmetic Progression
- Check whether Arithmetic Progression can be formed from the given array
- Count of AP (Arithmetic Progression) Subsequences in an array
- Minimum De-arrangements present in array of AP (Arithmetic Progression)
- Program for N-th term of Arithmetic Progression series
- Program to print Arithmetic Progression series
- PHP program to print an arithmetic progression series using inbuilt functions
- Longest string in non-decreasing order of ASCII code and in arithmetic progression
- Longest arithmetic progression with the given common difference
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Convert given array to Arithmetic Progression by adding an element
- Change one element in the given array to make it an Arithmetic Progression
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Minimum elements inserted in a sorted array to form an Arithmetic progression
- Count common elements in two arrays which are in Arithmetic Progression
- Find the missing number in unordered Arithmetic Progression
- Longest subarray forming an Arithmetic Progression (AP)
- Longest subsequence forming an Arithmetic Progression (AP)
- Count of subarrays forming an Arithmetic Progression (AP)

