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


proc nonrec sum_squares([*] int arr) ulong:
    ulong sum, item;
    word i, len;
    sum := 0;
    len := dim(arr,1);
    if len>0 then
        for i from 0 upto len-1 do 
            item := |arr[i];
            sum := sum + item * item
        od
    fi;
    sum
corp
 
proc nonrec main() void:
    type A0 = [0] int, 
         A1 = [1] int, 
         A5 = [5] int;
 
    writeln(sum_squares(A0()));
    writeln(sum_squares(A1(42)));
    writeln(sum_squares(A5(1,2,3,4,5)))
corp