I've been doing a function to calculate the sum of the first number (x0) with the ratio (r) by multiplying by a number (n) of times, like this function:
double sum_arithmetic(double x0, double r, int n)
{
return n == 0 ? 0 : x0 + sum_arithmetic(x0 + r, r, n-1);
}
For example, when x0 = 6, r = 3, n = 3, the result is 27 because it is 6 + 9 + 12, but now I want the same function type for the sum of the squares, to compute the sum x ^ 2 (x + 1) ^ 2 + ... + (x + n-1) ^ 2, for xen data, but I'm not getting how to get to this function: /