How would one write the geometric series
a + a r + a r2 + … + a rN-1
as an expression in C?
At the moment I have the code
where a is the first value in the series, N is the number of values in the series and r is the common ratio, but this only prints the last value of the series.Code:sum = a * (pow(r, N - 1));