#include <iostream>
using namespace std;
double geometricSum(double a, double x, int n) {
double sum = 0.0;
double power = 1.0 / x; // Start from x^(-1)
for (int i = 0; i <= n; ++i) {
sum += a * power;
power *= x; // Next: x^(i - 1 + 1) = x^i
}
return sum;
}
int main() {
double a, x;
int n;
cout << "Enter value of a (initial coefficient): \n";
cin >> a;
cout<<a;
cout << "Enter value of x (base): \n";
cin >> x;
cout<<x;
cout << "Enter value of n (number of terms - 1): \n";
cin >> n;
cout<<n;
double result = geometricSum(a, x, n);
cout << "Geometric sum S = " << result << endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: