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


/*NetRexx *************************************************************
* program to sum the squares of a vector of fifteen numbers.
* translated from REXX
* 14.05.2013 Walter Pachl
**********************************************************************/
numeric digits 50                   /*allow 50-digit # (default is 9)*/
v='-100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12' /* vector with some #s.     */
n=v.words()
x=''
sum=0                               /*initialize   SUM   to zero.    */
                                    /*if vector is empty, sum = zero.*/
loop Until x=''                     /*loop until list is exhausted   */
  Parse v x v                       /* pick next number              */
  If x>'' Then                      /* there is a number             */
    sum=sum + x**2                  /*add its square to the sum.     */
  end
say "The sum of" n "elements for the V vector is:" sum