C Program to check if a Number Is Even or odd

Check if a Number is Even or odd in C

Given an integer input, the objective is to write a code to Check if a Number is Even or odd in C Language.

For Instance,

Input: Num = -5

Output: The number is Negative

Check if a Number is Even or odd in C

Given an integer input, the objective is to check whether the given integer is Even or odd. In order to do so we have the following methods:

  • Method 1: Using Brute Force
  • Method 2: Using Nested if-else Statements
  • Method 3: Using the ternary operator

C Program to Check Whether a Number is Even or Odd

The number is Even or Odd Program in C

We can determine whether a number is Even or Odd in C using different methods.

Method 1: Using Modulus Operator

#include <stdio.h>
int main () {
    int number;
    printf ("Insert a number \n");
    scanf ("%d", &number);
    if (number % 2 == 0)
        printf ("Even");
    else
        printf ("Odd");
    return 0;
}
            

Output:

Insert a number
10
Even
            

Method 2: Using Ternary Operator

#include <stdio.h>
int main () {
    int number;
    printf ("Insert a number \n");
    scanf ("%d", &number);
    number % 2 == 0? printf ("Even"):printf ("Odd");
    return 0;
}
            

Output:

Insert a number
15
Odd
            

Method 3: Using Bitwise Operator

#include <stdio.h>
int isEven(int num) {
    return (!(num & 1));
}
int main() {
    int num;
    printf("Enter the number: ");
    scanf("%d",&num);
    isEven(num)? printf ("Even"):printf ("Odd");
    return 0;
}
            

Output:

Insert a number
5
Odd
            
Easy aceess next quctions
Getting Started

Positive or Negative number: C C++ Java Python

Even or Odd number: C C++ Java Python

Sum of First N Natural numbers: C C++ Java Python

Sum of N natural numbers: C C++ Java Python

Sum of numbers in a given range: C C++ Java Python

Greatest of two numbers: C C++ Java Python

Greatest of the Three numbers: C C++ Java Python

Leap year or not: C C++ Java Python

Prime number: C C++ Java Python

Prime number within a given range: C C++ Java Python

Sum of digits of a number: C C++ Java Python

Reverse of a number: C C++ Java Python

Palindrome number: C C++ Java Python

Armstrong number: C C++ Java Python

Armstrong number in a given range: C C++ Java Python

Harshad number: C C++ Java Python

Abundant number: C C++ Java Python

Friendly pair: C C++ Java Python