C Program to Find Sum of Geometric Progression Series

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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