Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Geometric Progression Series
1.1.
Example 
2.
 
3.
 
4.
 
5.
 
6.
Algorithm for Sum of Geometric Progression Series
7.
Code:
8.
Output:
9.
Time Complexity 
10.
Space Complexity 
11.
FAQs
12.
Key Takeaways
Last Updated: Mar 27, 2024

Sum of Geometric Progression Series

Author Apoorv
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Geometric Progression Series

  • Geometric series, commonly known as GP (Geometric Progression) is a sequence in which each succeeding phrase has a constant ratio between them.
  • The constant ratio is an arbitrary constant between every two numbers in the geometric series which is multiplied by the last number in the sequence to get the following number.

Example 

Geometric Sequence : 2, 4, 8,16, 32……. 

Consider a geometric series:

2+4+8+16+32 …

Here we have to find the last term, and we also need to calculate the Sum of Geometric Progression Series. There are a total of 10 terms in the series.

As you can see the first term i.e, a is equal to 2,

and the common ratio i.e, r is (4/2) i.e, 2

a1 = 2

a2 = a1*r = 2*2 = 4

a3 = a1*r² = 2*2*2 = 8 

Since an = ar⁽ⁿ⁻¹⁾,

an = 2*2⁽¹⁰⁻¹⁾ = 2¹⁰

Therefore the last term is 1024. 

Since this series is a finite series we will use the finite series formula to calculate the sum.

Sum = a(1-rⁿ)/(1-r) = a(rⁿ-1)/(r-1) = 2(2¹⁰-1)/(2-1) = 2(1024-1) = 2046 , So the Sum of Geometric Progression Series in this example is 2046.

Geometric Sequence a, ar, ar, ar, ar..... am
Geometric Series a +ar+ar+ar+ar+...+ am
First Term a
Common Ratio  r
nth term a*rn-1
Sum of Geometric Progression Series a*(1-rn)/(1-r)
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

 

 

 

 

You can also read about dynamic array in c and C Static Function.

Algorithm for Sum of Geometric Progression Series

  1. Start
  2. Declare the variables that depict the first term of the series, the total number of terms, and the common ratio for the geometric series.
  3. Use a for loop that will calculate the sum.
  4. Declare two variables for sum and element.
  5. Update both the elements in each iteration
  6. At the end display the calculated sum.
  7. Stop

Code:

// C Program to find the Sum of Geometric Progression Series 
#include <stdio.h>
#include<math.h>
int main ()
{


    // First number of gp series;
    int a = 2;


    // Common ratio for the gp series
    int r = 2;


    // Total number of terms in the gp series
    int n = 10;


    // This will store the total sum of Geometric Progression Series
    float sum = 0;


    // Variable for iteration in the loop
    int i ;


    // Variable to update the gp term initially it will be first term
    int var = a;


    // Print the series
    printf ("The G.P Series is  :  ");
    for (i = 0; i < n; i++)
    {
        printf ("%d  ", var);


        //Update the sum in each iteration
        sum = sum + var;


        //Update the term in each iteration     
        var = var * r;      
    }


    //Print the sum
    printf ("\nThe Sum for Geometric Progression Series =  %f\n", sum);
    return 0;
}

Output:

The G.P Series is  :  2  4  8  16  32  64  128  256  512  1024  
The Sum for Geometric Progression Series =  2046.000000

Time Complexity 

O(N)

The time complexity to find the sum of Geometric Progression Series is O(N), where 'N' is the total number of terms in the series.Since we are using a loop for iteration on all the terms to print the sum of the Geometric Progression Series, it will cost linear time complexity.

Read More - Time Complexity of Sorting Algorithms

Space Complexity 

O(1)

The space complexity to print the sum of the Geometric Progression Series is O(1), Since we have not used any extra data structure to store the elements and neither there are recursive calls so the space complexity for the above solution is constant. 

Also read, Tribonacci Series and Short int in C Programming

FAQs

  1. What are real-life applications of the sequence and series?
    Ans: Arithmetic sequences are used in everyday life for various reasons, including assessing the capacity of an auditorium, calculating predicted revenues from working for a firm, and constructing wood heaps using stacks of logs. Arithmetic sequences are algebra and geometry tools that aid mathematicians and others in problem-solving. 
  2. What is the geometric mean of two numbers?
    Ans: Geometric Mean is the average of two numbers in a geometric sequence. If x and y are the sequence's two numbers, then the geometric mean is GM = √xy.

Key Takeaways

In this article, we have extensively discussed the solution to print Sum of Geometric Progression Series in c along with its time and space complexity.

Check out this problem - Two Sum Problem
Also read reverse a number.
Until then, All the best for your future endeavours, and Keep Coding. "We hope that this blog has helped you enhance your knowledge regarding this problem, and if you would like to learn more, check out our articles on  Coding Ninjas Studio. Do upvote our blog to help other ninjas grow. Happy Coding!”

Previous article
C Program For Sum of AP Series
Next article
Fibonacci Series Program in C
Live masterclass