Calculate the sum of A.P. Series

C program to calculate a sum of A.P. without using formula.

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, sum=0;
    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);

	for(i=1;i<=n;i++)
	{
		term = a + ((i-1) * d);
		sum = sum + term;
		printf("Term number %d is %d\n",i,term);
	}

	printf("Sum of the A.P. is %d",sum);
	getch();
}

Output

Enter the first term of A.P.    :4
Enter the common difference of A.P.     :3
Enter the number of terms A.P.  :8
Term number 1 is 4
Term number 2 is 7
Term number 3 is 10
Term number 4 is 13
Term number 5 is 16
Term number 6 is 19
Term number 7 is 22
Term number 8 is 25
Sum of the A.P. is 116