Given Mth and Nth term of an arithmetic progression. The task is to find the sum of its first p terms.
Input: m = 6, n = 10, mth = 12, nth = 20, p = 5
Input:m = 10, n = 20, mth = 70, nth = 140, p = 4
Approach: Let a is the first term and d is the common difference of the given AP. Therefore
mth term = a + (m-1)d and nth term = a + (n-1)d
From these two equations, find the value of a and d. Now use the formula of sum of p terms of an AP.
Sum of p terms =
( p * ( 2*a + (p-1) * d ) ) / 2;
Below is the implementation of the above approach:
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.
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Find Pth term of a GP if Mth and Nth terms are given
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Find n terms of Fibonacci type series with given first two terms
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Find the Mth element of the Array after K left rotations
- Mth element after K Right Rotations of an Array
- Number of quadruples where the first three terms are in AP and last three terms are in GP
- Count the occurrence of Nth term in first N terms of Van Eck's sequence
- Find the sum of all the terms in the n-th row of the given series
- Sum of first n terms of a given series 3, 6, 11, .....
- Program to print the sum of the given nth term
- Sum of all the numbers in the Nth row of the given triangle
- Program to convert given number of days in terms of Years, Weeks and Days
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Minimum number of power terms with sum equal to n
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Sum of the series 0.6, 0.06, 0.006, 0.0006, ...to n terms
- Sum of the series 0.7, 0.77, 0.777, ... upto n terms
- Sum of series 2/3 - 4/5 + 6/7 - 8/9 + ------- upto n terms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.