Home >>VB.Net Programs >VB.Net program to check the given number is even or odd
We will read a number from the user here and then find that the given number is EVEN or ODD and then print a suitable message on the screen of the console.
Program :
Below is the source code to check that the specified number is even or odd. The program given is compiled and successfully executed.
Example
Module Module1
Sub Main()
Dim num As Integer = 0
Console.Write("Enter Your number: ")
num = Integer.Parse(Console.ReadLine())
If num Mod 2 = 0 Then
Console.WriteLine("Given number is EVEN")
Else
Console.WriteLine("Given number is ODD")
End If
End Sub
End Module
Explanation:
We created a Module1 module in the above program that contains a Main Method method (). We generated an integer variable num with an initial value of 0, in the Main() method.
Console.Write("Enter number: ") num = Integer.Parse(Console.ReadLine())
We read the value of the user's variable num in the above code.
If num Mod 2 = 0 Then Console.WriteLine("Given number is EVEN") Else Console.WriteLine("Given number is ODD") End If
In the code above, we use EVEN or ODD if statements are used to check the specified number, and then we print a suitable message on the console screen.