ADVERTISEMENT
ADVERTISEMENT

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

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

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


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.