Task

Write a program to find the sum of squares of a numeric vector.

The program should work on a zero-length vector (with an answer of   0).



Related task

   Mean


real
squaredsum(list l)
{
    integer i;
    real s;
 
    s = 0;
    i = -~l;
    while (i) {
        s += sq(l[i += 1]);
    }
 
    s;
}
 
integer
main(void)
{
    list l;
 
    l = list(0, 1, 2, 3);
 
    o_form("~\n", squaredsum(l));
    o_form("~\n", squaredsum(list()));
    o_form("~\n", squaredsum(list(.5, -.5, 2)));
 
    0;
}