C Program to Find Sum of Geometric Progression Series

Find the sum of GP or geometric progression series in the c program; Through this tutorial, we will learn how to find sum of GP series or geometric progression series using formula, for loop and function in c programs.

Programs to Find Sum of Geometric Progression Series in C

  • C Program to Find Sum of Geometric Progression Series using Formula
  • C Program to Find Sum of Geometric Progression Series using For Loop
  • C Program to Find Sum of Geometric Progression Series using Function

C Program to Find Sum of Geometric Progression Series using Formula

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

    int a, n, r;
    float tn, sum = 0;

    printf(" Please Enter First Number of an G.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this G.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Ratio:  ");
    scanf("%d", &r);

    sum = (a * (1 - pow(r, n ))) / (1- r);
    tn = a * (pow(r, n - 1));

    printf("\n The Sum of Geometric Progression Series =  %.2f", sum);
    printf("\n The tn Term of Geometric Progression Series = %.2f \n", tn);
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an G.P Series:  1
Please Enter the Total Numbers in this G.P Series:  5
Please Enter the Common Ratio:  2
The Sum of Geometric Progression Series =  31.00
 The tn Term of Geometric Progression Series = 16.00 

C Program to Find Sum of Geometric Progression Series using For Loop

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

    int a, n, r, value, i;
    float sum = 0;

    printf(" Please Enter First Number of an G.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this G.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Ratio:  ");
    scanf("%d", &r);

    value = a;
    printf("G.P Series  :  ");
    for(i = 0; i < n; i++)
    {
        printf("%d  ", value);
        sum = sum + value;
        value = value * r;
    }
    printf("\n The Sum of Geometric Progression Series =  %f\n", sum);
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an G.P Series:  2
Please Enter the Total Numbers in this G.P Series:  5
Please Enter the Common Ratio:  2
G.P Series  :  2  4  8  16  32
 The Sum of Geometric Progression Series =  62.000000

C Program to Find Sum of Geometric Progression Series using Function

/* C Program to find Sum of Geometric Progression Series */
#include <stdio.h>
#include<math.h>
int sumofGP(int a, int n, int r)
{
    int sum = (a * (1 - pow(r, n))) / (1- r);
    return sum;
}

int main() {

    int a, n, r;
    float sum = 0;

    printf(" Please Enter First Number of an G.P Series:  ");
    scanf("%d", &a);
    printf(" Please Enter the Total Numbers in this G.P Series:  ");
    scanf("%d", &n);
    printf(" Please Enter the Common Ratio:  ");
    scanf("%d", &r);

    sum = sumofGP(a, n, r);
    printf("\n The Sum of Geometric Progression Series =  %f\n", sum);
    return 0;
}

The output of the above c program; is as follows:

Please Enter First Number of an G.P Series:  2
Please Enter the Total Numbers in this G.P Series:  5
Please Enter the Common Ratio:  2
The Sum of Geometric Progression Series =  62.000000

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *