C Program to Check Whether a Number is Even or Odd

हेलो फ्रेंड्स आज इस पोस्ट में हम सी लैंग्वेज की मदद Even और Odd चेक करने वाला एक प्रोग्राम बनाएंगे | इस प्रोग्राम में हम यूजर से कोई नंबर एंटर कराएँगे फिर हम चेक करेंगे की यूजर दयारा एंटर किया गया नंबर है Even Number या Odd Number है | Even और Odd चेक करने के लिए मैं आपको 6 अलग-अलग तरीके से प्रोग्राम बना के बताने वाला हूँ |

C Program to Check Whether a Number is Even or Odd

5 Different Way to Check Whether a Number is Even or Odd

  1. Using if else or Modulus operator
  2. Using Bitwise operator
  3. Without using bitwise or modulus operator
  4. Using the Ternary Operator or using conditional operator
  5. Using function

आइये अब हम इन सभी तरीको से Even Number और Even Number चेक करना वाला प्रोग्राम बनाते है |

1. Write A C Program to Check Whether a Number is Even or Odd Using if else or Modulus operator (%)

Algorithm-:

  1. Program Start
  2. Declaration of variable
  3. Enter the number
  4. Assign the value in variable
  5. Check condition
  6. Give answer according to condition
  7. Program End

Flowchart -:

C Program to Check Whether a Number is Even or Odd Using if else or Modulus operator (%)

C Program to Check Whether a Number is Even or Odd Using if else or Modulus operator (%)

/* C Program to check whether the input integer number 
    is even or odd using if else or the modulus operator (%)
 */
#include<stdio.h>
#include<conio.h>
void main()
{
    int x;   // This variable X is to store the input number 
    printf("Enter a number\n");
    scanf("%d",&x);
    if(x%2==0)   // Modulus (%) returns remainder
        printf("Even number");
    else
        printf("Odd number");
    getch();
}

Output -:

Enter a number
187
odd number

2. Write A C Program to Check Whether a Number is Even or Odd Using Using Bitwise operator

/* C Program to check if number is even or odd
   using bitwise operator
 */
#include<stdio.h>
#include<conio.h>
void main()
{
    int N;
    printf("Enter a number\n");
    scanf("%d",&N);
    // If N & 1 is true 
    if(N&1)
        printf("Odd number");
    // Otherwise 
    else
        printf("Even number");
    getch();
}

Output -:

Enter a number
18
Even number

3. Write A C Program to Check Whether a Number is Even or Odd without using bitwise or modulus operator

/* C Program to check if number is even or odd
    without using bitwise or modulus operator
 */
#include<stdio.h>
#include<conio.h>
void main()
{
    int Num;
    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");
    getch();
}

Output -:

Enter a number
157
Odd number

4. Write A C Program to Check Whether a Number is Even or Odd Using the Ternary Operator or conditional operator

/* C Program to check whether the input integer number
    is even or odd Using the Ternary Operator or conditional operator
 */
#include<stdio.h>
#include<conio.h>
void main()
{
    int num;   // This variable X is to store the input number
    printf("Enter a number\n");
    scanf("%d",&num);
   num%2==0?printf("Even number"):printf("Odd number");
    getch();
}

Output -:

Enter a number
1211
Odd number

5. Write A C Program to Check Whether a Number is Even or Odd Using function

/* C Program to check whether the input integer number
    is even or odd Using function
 */
#include<stdio.h>
#include<conio.h>
void iseven(int num)
{
 if(num%2==0)
        printf("Even number");
 else
        printf("Odd number");
}
void main()
{
    int x;   // This variable X is to store the input number
    printf("Enter a number\n");
    scanf("%d",&x);
    iseven(x);
    getch();
}

Output -:

C Programming Exercises With Solutions (PDF)

Leave a Reply

Your email address will not be published. Required fields are marked *