Product Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Product 42


Objetive:

Create a Visual Basic (VB.net) program which asks the user for two integer numbers and displays their multiplication, but not using "*". You must use consecutive sums. (Hint: remember that 3*5 = 3+3+3+3+3 = 15)


Code:

Imports System
Public Class exercis40
    Public Shared Sub Main()
        Console.Write("Enter the first number: ")
        Dim n1 As Integer = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the second number: ")
        Dim n2 As Integer = Convert.ToInt32(Console.ReadLine())
        Dim result As Integer = 0
        Dim i As Integer = 0

        While i < n2
            result = result + n1
            i += 1
        End While

        Console.WriteLine("{0} X {1} = {2}", n1, n2, result)
    End Sub
End Class