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


' FB 1.05.0 Win64
 
Function SumSquares(a() As Double) As Double
  Dim As Integer length = UBound(a) - LBound(a) + 1
  If length = 0 Then Return 0.0
  Dim As Double sum = 0.0
  For i As Integer = LBound(a) To UBound(a)
    sum += a(i) * a(i)
  Next
  Return sum
End Function
 
Dim a(5) As Double = {1.0, 2.0, 3.0, -1.0, -2.0, -3.0}
Dim sum As Double = SumSquares(a())
Print "The sum of the squares is"; sum
Print 
Print "Press any key to quit"
Sleep