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

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

Write a program to check the given number is EVEN or ODD in VB.Net

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

Program :

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

Example


	Module Module1
    Sub Main()
        Dim result As String
        Dim num As Integer = 0

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

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

        Console.WriteLine(result)

        Console.ReadLine()
    End Sub
End Module
	
Output:
Enter Your number: 5
Given Number is ODD

Explanation:

We created a Module1 module in the program above that contains the Main() method. We generated two local variables arising from the Main() method and num. We read the value from the user after that, which is assigned to the variable num.

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

Here, we checked the remaining value after dividing the variable num by 2. If the remaining value is 0, either assign the message 'Number is EVEN' or assign the message 'Number is ODD' to the output of the variable. After that, the value of the result variable is written on the console screen.


No Sidebar ads