print G.P. series

C program to print G.P. series

Geometric progression (G.P.) or geometric sequence is a series of numbers in which common ratio (r) of any consecutive numbers (items) is always the same.
So, next element of the series is obtained by multiplying common ration (r) to the previous element.

Let, first term (a) of the G.P. series be 6 and common ratio (r) be 2
Then, Series would b
6, 12, 24, 48, ... and so on.

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

Program

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

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

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

	getch();
}

Output

Enter the first term of G.P.    :4
Enter the common ratio of G.P.  :2
Enter the number of terms G.P.  :6

G.P.Series      :4,  8,  16,  32,  64,  128,