ADVERTISEMENT
ADVERTISEMENT

VB.Net program to find the largest number between two numbers using a conditional operator

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

Here, we will read two 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 
'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 »



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.