C Program to Check number is Odd or Even

devquora
devquora

Posted On: Jan 27, 2023

C Program to Check number is Odd or Even

 

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:

  1. What is a number?
  2. What do you mean by Odd number?
  3. What do you mean by Even number?
  4. Demonstration for the logic to check number is Odd or Even
  5. Logic to Check number is Odd or Even
  6. C Program to Check number is Odd or Even with output
  7. 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

 Odd Even Demo

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.

Odd Even Checker Output

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.

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..