Determine if a Number is Odd or Even
Learn how to write pseudocode and create a flowchart to find out if a number is odd or even.
Problem statement
You have a number n, and you have to determine if n is odd or even.
The main steps in problem-solving
Understand the problem
Carefully read the problem statement. Also, think about the desired output. The output should be “odd” if the given number is odd and “even” if the given number is even.
Come up with a practical solution
Pick some specific examples of odd and even numbers. For instance, think about what differentiates 3 (an odd number) from a 4 (an even number). Observe that 3 is not divisible by 2, but 4 is. Recall that, as opposed to an even number, an odd number is not exactly divisible by 2. Hence, an effective solution to the problem is to divide the given number by 2. If the remainder is a non-zero, then the number is odd. Else, the number is even.
Get hands-on with 1200+ tech skills courses.