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


CARD FUNC SumOfSqr(BYTE ARRAY a BYTE count)
  BYTE i
  CARD res
 
  IF count=0 THEN
    RETURN (0)
  FI
 
  res=0
  FOR i=0 TO count-1
  DO
    res==+a(i)*a(i)
  OD
RETURN (res)
 
PROC Test(BYTE ARRAY a BYTE count)
  BYTE i
  CARD res
 
  res=SumOfSqr(a,count)
  Print("[")
  IF count>0 THEN
    FOR i=0 to count-1
    DO
      PrintB(a(i))
      IF i<count-1 THEN
        Put(' )
      FI
    OD
  FI
  PrintF("]->%U%E%E",res)
RETURN
 
PROC Main()
  BYTE ARRAY a=[1 2 3 4 5]
  BYTE ARRAY b=[10 20 30 40 50 60 70 80 90]
  BYTE ARRAY c=[11]
 
  Test(a,5)
  Test(b,9)
  Test(c,1)
  Test(c,0)
RETURN