Home >>VB.Net Programs >VB.Net program to find the largest number among three numbers
We'll read three 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 X As Integer = 0
Dim Y As Integer = 0
Dim Z As Integer = 0
Console.Write("Enter Your First number : ")
X = Integer.Parse(Console.ReadLine())
Console.Write("Enter Your Second number : ")
Y = Integer.Parse(Console.ReadLine())
Console.Write("Enter Your third number : ")
Z = Integer.Parse(Console.ReadLine())
result = If(
(X > Y AndAlso X > Z), X, If((Y > X AndAlso Y > Z), Y, Z)
)
Console.WriteLine("Here Largest Number amongs three is: {0}", result)
Console.ReadLine()
End Sub
End Module
Explanation:
We created a Module1 module in the program above that contains the Main() method. We created four local variables X, Y, Z and result that are initialized with 0. in the Main() method. We read the values of X, Y and Z after that.
result = If((X > Y AndAlso X > Z), X, If((Y > X AndAlso Y > Z), Y, Z) )
Here, to find the largest number of all the numbers and print the result on the console screen, we used a nested conditional operator.