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


 
class SumSquares
{
  static Int sumSquares (Int[] numbers)
  {
    Int sum := 0
    numbers.each |n| { sum += n * n }
    return sum
  }
 
  public static Void main () 
  {
    Int[] n := [,]
    echo ("Sum of squares of $n = ${sumSquares(n)}")
    n = [1,2,3,4,5]
    echo ("Sum of squares of $n = ${sumSquares(n)}")
  }
}
 