Overview:
An even number is an integer that can be divided by two whereas An odd number is an integer that can not be divided by two. Before going to write the c program to check whether the number is odd or even, let's understand What is number?What do you mean by Odd number? And What do you mean by Even number? Then, I will demonstrate the logic to check if the number is Odd or Even. After all, I will write the logic and C program to check if the number is odd or even with output.
Table of contents:
- What is a number?
- What do you mean by Odd number?
- What do you mean by Even number?
- Demonstration for the logic to check number is Odd or Even
- Logic to Check number is Odd or Even
- C Program to Check number is Odd or Even with output
- Conclusion
What is a number?
A number is a mathematical object used to count, measure, and label.
The original examples are the natural numbers 1, 2, 3, 4, and so forth.
Numbers can be represented in language with number words.
What do you mean by Odd number?
Odd numbers are whole numbers that cannot be divided exactly into pairs. Odd numbers, when divided by 2, leave a remainder of 1.
For instance,
1, 3, 5, 7, 9, 11, 13, 15 … are sequential odd numbers.
Odd numbers have the digits 1, 3, 5, 7 or 9 in their one’s place.
What do you mean by Even number?
An even number is an integer that can be divided by two and remain an integer or has no remainder.
Examples of even numbers are 2, 4, 6, 8.
An integer that is not an even number is an odd number.
Demonstration for the logic to check number is Odd or Even
Logic to Check number is Odd or Even
- Step 1: Input a number from user. Store it in some variable say num.
- Step 2: Check if number modulo division equal to 0 or not i.e. if(num % 2 == 0) then the number is even otherwise odd.
C Program to Check number is Odd or Even with output
#include int main() { int num; while(1) { /* Input number from user */ printf("\nEnter any number to check it is even or odd: "); scanf("%d", &num); /* Check if the number is divisible by 2 then it is even */ if(num % 2 == 0) { /* num % 2 is 0 */ printf("%d is Even.", num); } else { /* num % 2 is 1 */ printf("%d is Odd.", num); } } return 0; }
The output of the Program with code:
When the above code is executed, it produces the following results:
Enter any number to check it is even or odd: 153
153 is Odd.
Conclusion:
In this program, User Enter a number and check whether the given number is even or odd. Then, after successful compilation displays to check it is Odd or Even on the screen. The output of this Program is given below:
Enter any number to check it is even or odd: 4
153 is Even.
Enter any number to check it is even or odd: 3
3 is Odd.