Q:

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

0

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

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

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

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.

Example 1:

    Input:
    Enter number: 12
    Output:
    12 is an EVEN number.

Example 2:

    Input:
    Enter number: 19
    Output:
    19 is an ODD number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now