Q : How to Find even or odd with use of algoritham ?
A : 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
______________________________________________________________________________________________________________________________________________________________________________________
Hope it helps.
Please correct me if i am wrong at any point.
Thanks for watch video. LIKE SHARE & SUBSCRIBE...
~ mr improver