- Write a C program to print geometric series till N
^{th}term - Write a C program to find sum of geometric series till N
^{th}term

**Geometric series** is a sequence of terms in which next term is obtained by multiplying common ration to previous term. The (n+1)^{th} term of GP can be calculated as

(n+1)^{th} = n^{th} x R

where **R** is the common ratio (n+1)^{th}/n^{th}

The formula to calculate N^{th} term of GP : t_{n} = a x r^{n-1}

where, **a** is first term of GP and **r** is the common ratio.

## C program to print geometric progression series and it's sum till N terms

In this program, we first take number of terms, first term and common ratio as input from user using scanf function. Then we calculate the geometric series using above formula(by multiplying common ratio to previous term) inside a for loop. We keep on adding the current term's value to sum variable.

/* * C program to generate Geometric Series and it's sum till Nth term */ #include <stdio.h> #include <stdlib.h> int main() { int first, ratio, terms, value, sum=0, i; printf("Enter the number of terms in GP series\n"); scanf("%d", &terms); printf("Enter first term and common ratio of GP series\n"); scanf("%d %d", &first, &ratio); /* print the series and add all elements to sum */ value = first; printf("GP SERIES\n"); for(i = 0; i < terms; i++) { printf("%d ", value); sum += value; value = value * ratio; } printf("\nSum of the GP series till %d terms is %d\n", terms, sum); getch(); return 0; }

**Program Output**

Enter the number of terms in GP series 6 Enter first term and common ratio of GP series 2 4 GP SERIES 2 4 8 16 32 64 Sum of the GP series till 6 terms is 126

**Related Topics**