write a C++ program that uses a while loop to both display each term and determine the sum of a geometric series having a=1, r=0.5, n=10. Make sure your program displays the value it has calculated.
a+ ar + apow(r, 2) + ... + arpow(r, n-1)
#include <cstdio>
using namespace std;
int main(int argc, char *argv[])
{
double a = 1, r = 0.5, s = 0;
int n = 10;
for (int i = 0; i < n; i++)
{
& printf("a_%d = %lf\n", i, a); //display current term
& s += a; // add it to sum
& a *= r; // calculate next term
}
printf("s = %lf\n", s); // display total sum
return 0;
}