Home » ALGORITHM » ALGORITHM TO CHECK EVEN AND ODD NUMBERS

# ALGORITHM TO CHECK EVEN AND ODD NUMBERS

A number is said to be even number if it leaves no remainder when divided by 2. There is an alternative definition of even number and it is as a number having any number from 0, 2, 4, 6 and 8 at its ones place is an even number. Examples of even numbers are 12, 66, 456, 9900 and 12342 etc. An odd number leaves a remainder when it is divided by 2. All those numbers having any one from 1, 3, 5, 7 and 9 at their ones places are also called odd numbers.

(Even and Odd Numbers) Suppose N is a positive Integer. And this algorithm checks whether N is even or odd. Number N will be Even if it leaves remainder 0 when divided by 2. Otherwise N will be odd. To find the remainder of N when divided by 2 Modulo operator is used. The statement N%2 gives remainder.

Step 1: Start

Step 2: [ Take Input ] Read: N

Step 3: Check: If N%2 == 0 Then

Print : N is an Even Number.

Else

Print : N is an Odd Number.

Step 4: Exit

METHOD TWO:

By alternative definition of even numbers the algorithm to check even and odd numbers can be done as. First we have to find the ones digit of the number then we need to compare the ones digit by 0, 2, 4, 6 and 8. If if ones digit is any one from 0, 2, 4, 6 and 8 then number is even otherwise it is odd number. We have to use OR operator to do all comparison in one If Statement. The algorithm is as follows.

Step 1: Start

Step 2: [ Take Input ] Read: N

Step 3: Compute: X = N%10 [ Here X stores ones digit ]

Step 4: Check If: X == 0 OR X == 2 OR X == 4 OR X == 6 OR X == 8 Then

Print: N is an Even Number.

Else

Print: N is an Odd Number.

[ End of If Else Structure ]

Step 5: Exit

FIRST METHOD:

SECOND METHOD:

### Related Posts

• ALGORITHM AND FLOWCHART FOR COMPOSITE NUMBER Those numbers which are divisible by other than itself and 1 are known as composite numbers. The number 4 can is divisible by 1, 2 and 4 therefore 4 is a composite number. But 7 is […] Posted in ALGORITHM
• ALGORITHM FOR PALINDROME Any word, number or phrase which reads same from both ends is palindrome. For example 77, 121, 1331 and 12321 are palindrome numbers. Similarly Dalda and Madam are palindrome […] Posted in ALGORITHM
• ALGORITHM TO FIND FACTORIAL The product of positive integers from 1 to N is called factorial N. It can also be defined as The factorial of a number N is defined as the product of first N Natural Numbers. Factorial N […] Posted in ALGORITHM
• ALGORITHM TO FIND SUM OF DIGITS OF A NUMBER (Sum Of Digits Of A Number) Suppose N is an integer. This algorithm adds the digits of number N. As for example if N is 12345 then Sum of digits will be 15 by performing operation 1 + 2 + […] Posted in ALGORITHM