Home >>VB.Net Programs >VB.Net program to find the largest number between two numbers

VB.Net program to find the largest number between two numbers

Write a Program to find the largest number between two numbers in VB.Net

We'll read two integers here and check the largest number and print it on the screen of the console.

Program :

Below is the source code for finding the largest number of the two numbers. The program given is compiled and successfully executed.

Example


	Module Module1
    Sub Main()
        Dim result As Integer = 0
        Dim num1 As Integer = 0
        Dim num2 As Integer = 0

        Console.Write("Enter Your First number : ")
        num1 = Integer.Parse(Console.ReadLine())

        Console.Write("Enter Your Second number : ")
        num2 = Integer.Parse(Console.ReadLine())

        result = If((num1 > num2), num1, num2)

        Console.WriteLine("Here Largest Number is: {0}", result)

        Console.ReadLine()
    End Sub
End Module
	
Output:
Enter Your first number : 10
Enter Your Second number : 30
Here Largest Number is: 30

Explanation:

We created a Module1 module in the program above that contains the Main() method. Three local variables num1, num2, and the result, initialized with 0, were generated in the Main() method. Following that, we read the num1 and num2 values. After that, both num1 and num2 are compared and assigned to the result variable and the result value is written on the console screen.


No Sidebar ads