ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

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.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

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.