In this tutorial you will learn about the C Program to Find Sum of Geometric Progression Series and its application with practical example.
C Program to Find Sum of Geometric Progression Series
In this tutorial, we will learn to create a C program that will Find the Sum of the Geometric Progression Series using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C Programming.
- Functions in C Programming.
What is Geometric Progression?
The Geometric progression is a series in mathematics that starts from a point and the second term is having a common ratio, and this series continues till the endpoint with the common ratio.
It means if the first term is 1 and then the ratio of 5 then the next term will be 5 then the next term will be 5*5.
Programs to Find Sum of Geometric Progression Series:-
In this program, First, we take the first term of the Geometric progression. Then we will take the total number of terms in G.P. At last we will take the common ratio from the user. Now we will generate the Geometric progression using the for loop and the mathematical expressions. Then will print the sum of the Geometric progression.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* C Program to find Sum of Geometric Progression Series */ #include <stdio.h> #include<math.h> int main() { //declaring the required variable for the program int First_term, no, rt; float tn, sum = 0; //Taking the Enter First Number of an G.P Series printf(" Please Enter First Number of an G.P Series: "); scanf("%d", &First_term); //Taking the Total Numbers in this G.P Series printf(" Please Enter the Total Numbers in this G.P Series: "); scanf("%d", &no); //Taking the Common Ratio printf(" Please Enter the Common Ratio: "); scanf("%d", &rt); //Findind the sum of g.p. sum = (First_term * (1 - pow(rt, no ))) / (1- rt); tn = First_term * (pow(rt, no - 1)); //printing the sum of series printf("\n The Sum of Geometric Progression Series = %.2f", sum); //printing the last term. printf("\n The tn Term of Geometric Progression Series = %.2f \n", tn); return 0; } |
Output:-
In the above program, we have first initialized the required variable
- first_term = it will hold the integer value.
- no = it will hold the integer value.
- rt= it will hold the integer value.
- tn = it will hold the float value.
- i = it will hold the integer value to control the array.
Taking the first term, common ratio, and the number of terms from the user.
Generating the geometric progression using the loops and calculating the sum.
Program Code for Printing the sum of series.