Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

C program to find nth term using Arithmetic progrssion

In C programming language, the nth term of an arithmetic progression can be calculated using the following formula:

an = a1 + (n-1)d

where an is the nth term of the progression, a1 is the first term, n is the position of the term to be found, and d is the common difference between consecutive terms.

Here is an example program to find the nth term of an arithmetic progression using the above formula:

#include <stdio.h>

int main() {
  int a1, d, n, an;
  printf("Enter the first term: ");
  scanf("%d", &a1);
  printf("Enter the common difference: ");
  scanf("%d", &d);
  printf("Enter the position of the term to be found: ");
  scanf("%d", &n);
  
  // calculate the nth term using the formula
  an = a1 + (n - 1) * d;

  printf("The %dth term of the arithmetic progression is %d\n", n, an);
  return 0;
}

In this program, we first declare four integer variables a1, d, n, and an. We ask the user to input the values of a1, d, and n using the scanf() function.

Then, we calculate the value of an using the formula an = a1 + (n-1)d. Finally, we print the value of an using the printf() function.