Q:

Odd or Even Program In C (7 Different Ways)

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  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

All Answers

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

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

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

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

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

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Prime Number Program In C (3 Simple Ways)... >>
<< Leap Year Program In C (5 Different Ways)...