Print A.P. Series

C program to print A.P. Series

Arithmetic progression (A.P.) or arithmetic sequence is a sequence of number where the difference between the two consecutive terms is same.
So, next term is obtained by adding common difference (d) to previous term.

Let, first term (a) of the A.P. series be 7 and common difference (d) be 2
Then, Series would be
7, 9, 11, 13, 15, ... and so on.

So, nth term (tn) will be calculated as follows:
t1 = a
t2 = a + (2 - 1) * d
t3 = a + (3 - 1) * d
...
tn = a + (n - 1) * d

Program

#include<stdio.h>
#include<conio.h>
void main()
{
	int a, d, n;
    int i, term;

	printf("Enter the first term of A.P.\t:");
	scanf("%d",&a);
	printf("Enter the common difference of A.P.\t:");
	scanf("%d",&d);
	printf("Enter the number of terms A.P.\t:");
	scanf("%d",&n);

    printf("\nA.P.Series\t:");
	for(i=1;i<=n;i++)
	{
		term = a + ((i-1) * d);
		printf("%d,  ",term);
	}

	getch();
}

Output

Enter the first term of A.P.    :5
Enter the common difference of A.P.     :2
Enter the number of terms A.P.  :6

A.P.Series      :5,  7,  9,  11,  13,  15,