Find Nth-term of an arithmetic progression

Given a first element a and common difference d of an arithmetic progression. Write a program to find the nth term in that progression. 

Example: 

a = 1, d = 2, n = 5
output: 9

a = 2, d = 5, n = 4
output: 17

Solution: 

Formula for finding nth term in an arithmetic progression:

Nth term = a + (n-1)*d.

Code:

Output:

a = 1, d = 2, n = 5
5th term: 9
a = 2, d = 5, n = 4
4th term: 17

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.