Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python code to check whether the number is odd or even using operators

C Check whether the number is odd or even using operators

Posted on September 25, 2020September 25, 2020

Table of Contents

  • C Check whether the number is odd or even using operators
    • C Check whether the number is odd or even
      • Check whether the number is odd or even – using modular operator
      • Check whether the number is odd or even – using divisional operator
      • Check whether the number is odd or even – using ternary operator
      • Check whether the number is odd or even – using bit wise operator
      • Check whether the number is odd or even – using shift operator

C Check whether the number is odd or even using operators

In this tutorial, we will discuss the Program to C Check whether the number is odd or even using operators

In this post, we are going to learn how to check whether the given number is odd or even number using operator in C language

C Check whether the number is odd or even

Check whether the number is odd or even – using modular operator

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num;//variable declaration
    printf("Enter a integer to check odd or even\n");
//the program Asks input from the user
    scanf("%d",&num);
//the integer entered by the user and it is stored in variable num

    if(num%2==0){
        printf("%d is even",num);
    }
    else{printf("%d is even",num);}
    getch();
    return 0;
}

When the above code is executed ,it produces the following result

case 1

Enter a integer to check odd or even
3500
3500 is even

case 2

Enter a integer to check odd or even
2345
2345 is odd

 

Check whether the number is odd or even – using divisional operator

Program 2

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int num;//variable declaration
    printf("Enter a integer to check odd or even\n");
//the program Asks input from the user
   scanf("%d",&num);
//the integer entered by the user and it is stored in variable num

    if((num/2)*2==num){
       printf("%d is even number",num);
    }
    else{printf("%d is odd number",num);}
    getch();
    return 0;
}

When the above code is executed ,it produces the following result

case 1

Enter a integer to check odd or even
3506
3506 is even number

case 2

Enter a integer to check odd or even
999
999 is odd number

 

Check whether the number is odd or even – using ternary operator

Program 3

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int num;//variable declaration
    printf("Enter a integer to check odd or even\n");
//the program Asks input from the user
   scanf("%d",&num);
//the integer entered by the user and it is stored in variable num

     (num%2==0)? printf("%d is even",num):printf("%d is odd",num);
    getch();
    return 0;
}

When the above code is executed ,it produces the following result

case 1

Enter a integer to check odd or even
5678
5678 is even

case 2

Enter a integer to check odd or even
6767
6767 is odd

 

Check whether the number is odd or even – using bit wise operator

Program 4

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int num;//variable declaration
    printf("Enter a integer to check odd or even\n");
//the program Asks input from the user
   scanf("%d",&num);
//the integer entered by the user and it is stored in variable num
if((num & 1)==0){
      printf("%d is even number",num);
    }
    else{printf("%d is odd number",num);}

    getch();
    return 0;
}

When the above code is executed ,it produces the following result

case 1

Enter a integer to check odd or even
4
4 is even number

case 2

Enter a integer to check odd or even
5
5 is odd number

Check whether the number is odd or even – using shift operator

Program 5

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num;//variable declaration
    printf("Enter a number to check even or odd\n");
//the program Asks input from the user
    scanf("%d",&num);
//the integer entered by the user and it is stored in variable num
    if((num>>1)<<1==num)
        printf("%d is Even number",num);
        else
         printf("%d is Odd number",num);
         getch();
    return 0;
}

When the above code is executed ,it produces the following result

Case 1

Enter a number to check even or odd
4321
4321 is Odd number

Case 2

Enter a number to check even or odd
4326
4326 is Even number

 

Suggested for you

Data type in C language

Variable in C language

Operator in C language

While loop in C language

 

Similar post

Java Program to check whether the number is odd or even using operators

C Program to check whether the number is odd or even using operators

C++ Program to check whether the number is odd or even using operators

Python Program to check whether the number is odd or even using operators

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes