ADVERTISEMENT
ADVERTISEMENT

VB.Net program to find the largest number among three numbers using conditional operator

Here, we are going to learn how to find the largest number among three numbers using conditional operator in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will read three integers and check the largest number and print that on the console screen.

Program/Source Code:

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 
'among three numbers.

Module Module1

    Sub Main()

        Dim result As Integer = 0
        Dim num1 As Integer = 0
        Dim num2 As Integer = 0
        Dim num3 As Integer = 0

        Console.Write("Enter number1: ")
        num1 = Integer.Parse(Console.ReadLine())

        Console.Write("Enter number2: ")
        num2 = Integer.Parse(Console.ReadLine())

        Console.Write("Enter number3: ")
        num3 = Integer.Parse(Console.ReadLine())

        result = If(
                    (num1 > num2 AndAlso num1 > num3), num1, If((num2 > num1 AndAlso num2 > num3), num2, num3)
                   )
        Console.WriteLine("Largest Number is: {0}", result)

        Console.ReadLine()
    End Sub

End Module

Output:

Enter number1: 10
Enter number2: 30
Enter number3: 20
Largest Number is: 30

Explanation:

In the above program, we created a module Module1 that contains Main() method. In the Main() method we created four local variables num1, num2, num3, and result that are initialized with 0. After that we read the values of num1, num2 and num3.

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

Here, we used a nested conditional operator to find the largest number among all the numbers and print the result on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.