Check if a given number is Even or Odd

Any number which is divisible by 2 is called as an Even number, and any number which is not divisible by 2 is called an Odd number. Examples of Even numbers are all multiples of 2 such as 2,4,6,8,10 .. and Odd numbers are 1,3,5,7,9,..


        public static string IsEvenOrOdd(int n)
        {
            if (n % 2 == 0)
                return "EVEN";
            else
                return "ODD";
        }
        

How it works:

For any given number, we divide the number by two and check the reminder. If the remainder is 0, then it means that the number is Even otherwise Odd.


Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *