VB.Net program to check the given number is EVEN or ODD using conditional operator

Here, we are going to learn how to check the given number is EVEN or ODD using conditional operator in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Checking EVEN or ODD using conditional operator

Here, we will check the entered number is EVEN or ODD with the help of a conditional operator.

VB.Net code to check the given number is EVEN or ODD using conditional operator

The source code to check the given number is EVEN or ODD using conditional operator is given below. The given program is compiled and executed successfully.

'VB.Net program to check given number is 
'EVEN or ODD using conditional operator.

Module Module1

    Sub Main()

        Dim result As String
        Dim num As Integer = 0

        Console.Write("Enter number: ")
        num = Integer.Parse(Console.ReadLine())

        result = If((num Mod 2 = 0), "Number is EVEN", "Number is ODD")

        Console.WriteLine(result)

        Console.ReadLine()
    End Sub

End Module

Output:

Enter number: 5
Number is ODD

Explanation:

In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created two local variables result and num. After that, we read the value from the user, which is assigned to the variable num.

result = If((num Mod 2 = 0), "Number is EVEN", "Number is ODD")

Here, we checked remainder after divide value of variable num by 2. If the remainder is 0 then assign the message "Number is EVEN" otherwise assign the "Number is ODD" message to the variable result. After that print value of variable "result" on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.