
Patrick B. answered 08/07/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <math.h>
void GeometricSeriesSum (double R, int nExpo, double * sum)
{
if (nExpo==0)
{
*sum=*sum+1;
}
else
{
*sum = *sum + pow(R,nExpo);
GeometricSeriesSum(R,nExpo-1,sum);
}
}
int main()
{
double sum=0;
double R = 1.0/3;
int nExpo=6;
GeometricSeriesSum(R,nExpo,&sum);
cout << sum << endl;
}