This is more of a how to read a math expression problem. It seems like in your example, m = 5, so the sums never reference beyond that.
I'm not entirely clear on your equation. Have tried Mathjax, but the formula is still not clear to me, but...
When translating a math expression to code, think of the summation sign (sigma) as equivalent to a for loop!
when writing the code, write (initially) in the most explicit way possible. For this problem code TWO for loops, one after the other, NOT nested. Each for loop does part of the calculation for g(k).
Get this to work for g(1). Then code a third for loop that wraps or surrounds the two loops you just got working. This loop will calculate g(1), g(2), etc. Note. if m is 5 and you only have 5 data points then you can only compute g(1), if m is 6 you can compute g(1) and g(2), etc.
Hope this helps, please post if you more information or questions.
To answer your comment, the following for loop implements a sum or sigma. Note. This is NOT exactly what your code should do, but it does demo using two for loops.
int g1; x = 0; y = 0;
int i;
// compute x = sum(g(i)) + sum(f(i))
// sum i = 0 to 2 [g(i)]
for (i=0; i < 3; i++) {x += g[i];}
// sum i = 0 to 1 [f(i)];
for (i=0; i < 2; i++) {y += f[i];}
g1 = x - y^2;