Sum of an Infinite Geometric Progression ( GP ) | C ++ program for the above approach ; Function to calculate the sum of an infinite Geometric Progression ; Case for Infinite Sum ; Store the sum of GP Series ; Print the value of sum ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findSumOfGP ( double a , double r ) { if ( abs ( r ) >= 1 ) { cout << " Infinite " ; return ; } double sum = a / ( 1 - r ) ; cout << sum ; } int main ( ) { double A = 1 , R = 0.5 ; findSumOfGP ( A , R ) ; return 0 ; }