English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Given the first term 'a', the common difference 'd', and the number of terms 'n' in the series. The task is to find the nth term of the series.
Therefore, before discussing how to write a program to address this issue, we should know what an arithmetic progression is.
Arithmetic progression or arithmetic sequence is a sequence of numbers in which the difference between two consecutive terms is the same.
as we have the first term, that is a = 5, difference1and the nth term we need to find should be3. Therefore, the series should be:5,6,7, so the output must be7.
Therefore, we can say that the arithmetic progression of the nth term will be similar to-
AP1 = a1 AP2 = a1 + (2-1) * d AP3 = a1 + (3-1) * d ..APn = a1 + (n-1) *
Therefore, the formula will be AP = a +(n-1)* d.
Input: a=2, d=1, n=5 Output: 6 Explanation: The series will be: 2, 3, 4, 5, 6 nth term will be 6 Input: a=7, d=2, n=3 Output: 11
We will use the method to solve the given problem-
With the first term A, common difference D and N as the series number.
Then through (A +(N-1)* D) Calculate the nth term
Return the output obtained from the above calculation.
Start Step 1 -> In function int nth_ap(int a, int d, int n) Return (a + (n - 1) * d) Step 2 -> int main() Declare and initialize the inputs a=2, d=1, n=5 Print The result obtained from calling the function nth_ap(a,d,n) Stop
#include <stdio.h> int nth_ap(int a, int d, int n) { //Use the formula to find //The nth term t(n) = a(1)+(n-1)* d- return (a + (n - 1) * d); } //Main Function int main() { //Starting Number int a = 2; //Common Points int d = 1; //The Nth Noun int n = 5; printf("The %dth term of AP :%d\n", n, nth_ap(a,d,n)); return 0; }
Output Result
The 5The 77th term of the series is: 6