Program to calculate sum of an Infinite Arithmetic | C ++ program for the above approach ; Function to find the sum of the infinite AGP ; Stores the sum of infinite AGP ; Print the required sum ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void sumOfInfiniteAGP ( double a , double d , double r ) { double ans = a / ( 1 - r ) + ( d * r ) / ( 1 - r * r ) ; cout << ans ; } int main ( ) { double a = 0 , d = 1 , r = 0.5 ; sumOfInfiniteAGP ( a , d , r ) ; return 0 ; }