Assigned Th 5/22/2008, due Fr 5/30 at 4pm. 50 points.
http://www.cs.nyu.edu/courses/summer08/G22.3033-002/
These are example solutions. Please keep in mind that often, there is not just one correct solution to a question. If you come up with different answers, then it may be that both your answers and these answers here are correct. Of course, these answers here may also contain mistakes. If you spot a mistake, please let me know so I can correct it.
Sub PrintArray(Arr() As String)
Debug.Print "PrintArray:"
For I% = 0 To UBound(Arr)
Debug.Print " " & I & " " & Arr(I)
Next I
End Sub
Sub Main()
Dim fruits(2) As String
fruits(0) = "apple"
PrintArray fruits
fruits(1) = "orange"
fruits(2) = "banana"
PrintArray fruits
End Sub
2 - (2 - 2 - 2 * 2)
Function EuclidDistance(A() As Double, B() As Double) As Double
EuclidDistance = 0
Dim I As Integer
For I = LBound(A) To UBound(A)
EuclidDistance = EuclidDistance + (A(I) - B(I)) ^ 2
Next I
EuclidDistance = EuclidDistance ^ 0.5
End Function
Sub AverageRows(Result() As Double, Rows() As Double)
Dim I As Integer, J As Integer
For I = LBound(Rows, 1) To UBound(Rows, 1)
Result(I) = 0
For J = LBound(Rows, 2) To UBound(Rows, 2)
Result(I) = Result(I) + Rows(I, J)
Next J
Result(I) = Result(I) / (1 + UBound(Rows, 2) - LBound(Rows, 2))
Next I
End Sub