Odd or Even Program In C (7 Different Ways)

In this article, we will make an Odd or Even Program In C. In this program first, we take a number from the user, then we will check whether the number entered by the user is Even or Odd.

To find Odd or Even, We’ll make this program in 7 different ways -:

  1. C Program to Find Even or Odd Using if else or Modulus Operator
  2. C Program to Check Even or Odd Using Bitwise Operator
  3. C Program to Check Even or Odd Without Using bitwise or modulus operator
  4. C Program to Check Even or Odd Using Conditional Operator or Ternary Operator
  5. C Program to Check Whether a Number is Even or Odd Using Function
  6. C Program to Check Even or Odd Using Switch Case
  7. C Program to Check Even or Odd Using goto statement

To make this program, we will use the following concept given below.

If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.

Now without wasting time let’s start programming.

Odd or Even Program In C

Odd or Even Program In C Using if else or Modulus Operator

Algorithm -:

  1. Program Start
  2. Declaration of variable (int x;)
  3. Input Number From the user
  4. Assign the value in variable
  5. Checking condition
  6. Give answer according to condition
  7. Program End

Flowchart

C Program to Find Even or Odd Using if else or Modulus Operator  - Flowchart

Program -:

//C Program to Find Even or Odd Using if else or Modulus Operator 

#include<stdio.h>
void main()
{
 // variable Declaration
    int x;  

//input number
    printf("Enter a number\n");
    scanf("%d",&x);

 //Checking Whether a Number is Even or Odd 
    if(x%2==0)   // Modulus (%) returns remainder
        printf("Even number");
    else
        printf("Odd number");

}

Output -:

Enter a number
87
Odd number

C Program to Check Even or Odd Using Bitwise Operator

Program -:

/*write a c program to check even or odd using bitwise operator in c */

#include<stdio.h>
void main()
{
    int N;

    //input number
    printf("Enter a number\n");
    scanf("%d",&N);

    // If N & 1 is true
    if(N&1)
        printf("Odd number");
    // Otherwise
    else
        printf("Even number");

}

Output -:

Enter a number
7
Odd number

C Program to Check Whether a Number is Even or Odd Without Using Bitwise or Modulus Operator

Program -:

//C Program to Check Whether a Number is Even or Odd 
//Without Using Bitwise or Modulus Operator

#include<stdio.h>
void main()
{
    int Num;
    
    //input number
    printf("Enter a number\n");
    scanf("%d",&Num);
   
    // If (Num/2)*2==Num is true 
    if((Num/2)*2==Num)
        printf("Even number");
    // Otherwise 
    else
        printf("Odd number");
}

Output -:

Enter a number
10
Even number

C Program to Check Even or Odd Using Conditional Operator or Ternary Operator

Program -:

//C Program to Check Even or Odd 
//Using Ternary Operator or Conditional Operator

#include<stdio.h>
void main()
{
 //variable declaration
  int num;  
  
  //input number
  printf("Enter a number\n");
  scanf("%d",&num);
 
 //using conditional operator checking odd even 
  num%2==0?printf("Even number"):printf("Odd number");
  
}

Output -:

Enter a Number
14
Even number

C Program to Check Whether a Number is Even or Odd Using Function

To make and understand this program made by function, first of all you need to know the basic of the function.

You can read about the function from here -: Function in C

Algorithm -:

  1. Program Start
  2. Declaration of variable (int x;)
  3. Input Number From the user
  4. Assign the value in variable
  5. Calling Function to check even or odd
  6. Check condition
  7. Give answer according to condition
  8. Program End

Program -:

//C Program to Check Whether a Number is Even or Odd
//Using Function

#include<stdio.h>
void iseven(int num)
{
 if(num%2==0)
        printf("Even number");
 else
        printf("Odd number");
}
void main()
{
    int x;  //variable declaration

    //input number
    printf("Enter a number\n");
    scanf("%d",&x);

    //calling function to check odd even
    iseven(x);

}

Output -:

Enter a number
2
Even number

C Program to Check Even or Odd Using Switch Case

Program -:

//C Program to check Even or Odd Using Switch Case Statement

#include<stdio.h>
void main()
{
 // variable Declaration
    int x,y;

  //input number
    printf("Enter a number\n");
    scanf("%d",&x);

 //Checking Whether a Number is Even or Odd
    if(x%2==0)   // Modulus (%) returns remainder
        y = 1;
    else
        y = 0;

    switch(y)
    {
        case 0: printf("%d is a odd number",x);
                break ;
        case 1: printf("%d is a even number",x);
                break;
    }

}

Output -:

Enter a number
6
6 is a even  number

C Program to Check Even or Odd Using goto statement

Program -:

//C Program to Find Even or Odd Using goto Statement

#include<stdio.h>
void main()
{
 // variable Declaration
    int x,y;

  //input number
    printf("Enter a number\n");
    scanf("%d",&x);

 //Checking Whether a Number is Even or Odd
   if (x%2 == 0)
        goto even;
    else
        goto odd;

even:
    printf("%d is a even number\n", x);
    exit(0);
odd:
    printf("%d is a odd number\n", x);
}

Output -:

Enter a Number 
13
13 is a odd number

Conclusion

So friends in this article We will make this program in various ways. These are as follows:

  1. C Program to Find Even or Odd Using if else or Modulus Operator
  2. C Program to Check Even or Odd Using Bitwise Operator
  3. C Program to Check Even or Odd Without Using bitwise or modulus operator
  4. C Program to Check Even or Odd Using Ternary Operator or Conditional Operator
  5. C Program to Check Whether a Number is Even or Odd Using Function
  6. C Program to Check Even or Odd Using Switch Case
  7. C Program to Check Even or Odd Using goto statement

If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment