Advertisement
More C# Resources
- Tutorials C# Tutorials
- Code C# Code
- Jobs C# Jobs
The best way to see if a given number is odd or even is to use the modulus operator (%). The modulus operator returns the remainder when dividing two numbers. So if you do a modulus of 6 % 2 you get 0 because 6 divided by 2 doesn’t have a remainder, therefore it’s even. If you do 3 % 2 the remainder will be 1, therefore the number is odd.
int Num = 5; |