Home »
VB.Net »
VB.Net Programs
VB.Net program to find the largest number between two numbers using a conditional operator
By Nidhi Last Updated : November 15, 2024
Finding the largest number among two numbers using a conditional operator
Here, we will read two integers and check the largest number and print that on the console screen.
VB.Net code to find the largest number between two numbers using a conditional operator
The source code to find the largest number between the two numbers is given below. The given program is compiled and executed successfully.
'VB.Net program to find the largest number
'between two numbers.
Module Module1
Sub Main()
Dim result As Integer = 0
Dim num1 As Integer = 0
Dim num2 As Integer = 0
Console.Write("Enter number1: ")
num1 = Integer.Parse(Console.ReadLine())
Console.Write("Enter number2: ")
num2 = Integer.Parse(Console.ReadLine())
result = If((num1 > num2), num1, num2)
Console.WriteLine("Largest Number is: {0}", result)
Console.ReadLine()
End Sub
End Module
Output:
Enter number1: 10
Enter number2: 30
Largest Number is: 30
Explanation:
In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created three local variables num1, num2, and result that are initialized with 0. After that, we read the values of num1 and num2. After that compare both num1 and num2 and assigned to the variable result and print the value of the result on the console screen.
VB.Net Basic Programs »