C program to find nth term in given terms. Use Arithmetic progrssion in the program.
An arithmetic progression is a sequence of numbers.
Arithmetic progression,
an = a1+(n-1)*d
an = the nᵗʰ term in the sequence
a1 = the first term in the sequence
d = the common difference between terms
/* C program to find nth term using
*Arithmetic progrssion
*/
#include <stdio.h>
int main()
{
int an, a1, n, d;
//3 7 11 15 19 23
a1 = 3; // First term
n = 6; // Number of terms
d = 4; //7-3
/*Formula of arithmetic progrssion
*an = a1+(n-1)d
*an -> nth term
*a1 -> first term
*n -> Number of terms
*d -> Difference of terms
*/
an = a1+(n-1)*d;
printf("nth term is =%d",an);
return 0;
}
Output:
nth term is =23
Post a Comment
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.