C program to check whether a given number is EVEN or ODD

C program for EVEN or ODD: Here, we are reading an integer number from the user and checking whether it is EVEN or ODD.

The numbers which are divisible by 2 are EVEN numbers and which are not divisible by 0 are not as ODD numbers.

Problem statement

Given an integer number and we have to check it is EVEN or ODD using C program.

Checking EVEN or ODD in C

To check whether given number is EVEN or ODD, we are checking modulus by dividing number by 2, if the modulus is 0, then it will be completely divisible by 2 hence number will be EVEN or its will be ODD.

Examples

Example 1:

Input:
Enter number: 12

Output:
12 is an EVEN number.

Example 2:

Input:
Enter number: 19

Output:
19 is an ODD number.

C program to check EVEN or ODD

/* c program to check whether number is even or odd*/
#include <stdio.h>
int main()
{
  
    int num;
 
    printf("Enter an integer number: ");
    scanf("%d",&num);
 
    /*If number is divisible by 2 then number 
    is EVEN otherwise number is ODD*/
 
    if(num%2==0)
        printf("%d is an EVEN number.",num);
    else
        printf("%d is an ODD number.",num);
 
    return 0;
}

Output

First Run:
Enter an integer number: 123
123 is an ODD number.

Second Run:
Enter an integer number: 110
110	 an EVEN number.

C Basic Programs »


Related Programs

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.