VB.Net program to check the given number is even or odd

Here, we are going to learn how to check the given number is even or odd in VB.Net?
Submitted by Nidhi, on December 03, 2020 [Last updated : February 18, 2023]

Checking Even/Odd in VB.Net

Here, we will read a number from the user and then find the given number is EVEN or ODD and then print an appropriate message on the console screen.

VB.Net code to check the given number is even or odd

The source code to check the given number is even or odd is given below. The given program is compiled and executed successfully.

'VB.Net program to check the given number is even or odd.

Module Module1
    
    Sub Main()
        Dim num As Integer = 0
        
        Console.Write("Enter 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

Output:

Enter number: 122
Given number is EVEN
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a method Main(). In the Main() method, we created an integer variable num with an initial value 0.

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

In the above code, we read the value of variable num from user.

If num Mod 2 = 0 Then
    Console.WriteLine("Given number is EVEN")
Else
    Console.WriteLine("Given number is ODD")
End If

In the above code, we use if statements to check the given number is EVEN or ODD, and then we printed an appropriate message on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





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