Ejercicio
Función Multiply & MultiplyR
Objetivo
Crea dos funciones, Multiplicar y Multiplicar, para calcular el producto de dos números usando sumas. La primera versión debe ser iterativa, y la segunda debe ser recursiva.
Código
Imports System
Public Class exercise133
Public Shared Function MultiplyR(ByVal n1 As Integer, ByVal n2 As Integer) As Integer
If n2 = 0 Then
Return 0
Else
Return n1 + MultiplyR(n1, n2 - 1)
End If
End Function
Public Shared Function Main(ByVal args As String()) As Integer
If args.Length <> 2 Then
Console.WriteLine("Enter two numbers!!")
Return 1
Else
Dim n1 As Integer = Convert.ToInt32(args(0))
Dim n2 As Integer = Convert.ToInt32(args(1))
Console.WriteLine(MultiplyR(n1, n2))
Return 0
End If
End Function
End Class