• If a number is divisible by 2 then is it an even number otherwise it is odd number.
  • Now we need to check a number is even or odd without using modulus or division operators in c programming language.
  • Yes we can check a number is even or odd without using division and modulus operators for that we need to use & operator
  • number &1 ==1 then it is an even number.
  • Let us check a number is even or not in c program using & operator.
  • Here is the example program for how to find even of odd number without using modulus in c programming language


Program #1: write a c program to check a number is even or odd without using modulus and division operators in c programming.
  • Even or odd program in c without using mod operator 

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int number;
  5.  
  6.     printf("Enter a number to check even or odd");
  7.     scanf("%d", &number);
  8.  
  9.     if((number & 1)==0)
  10.           printf("%d is even.", number);
  11.     else
  12.         printf("%d is odd.", number);
  13.         
  14.  
  15.     getch();
  16.     
  17. }

Output:


even or odd division modulus in c

  • We can check a number is even or odd without using modulus and division operator in c program
  • The another method is using shift operators
  •   number >> 1) <<1==number then it is even number
  • Like this we can find even or odd number without using modulus in c 

 Program #2: write a c program to check odd or even without using modulus operator

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int number;
  5.  
  6.     printf("Enter a number to check even or odd");
  7.     scanf("%d", &number);
  8.  
  9.     if(( number >> 1) <<1==number)
  10.           printf("%d is even.", number);
  11.     else
  12.         printf("%d is odd.", number);
  13.         
  14.  
  15.     getch();
  16.     
  17. }

Output:

  1. Enter a number to check even or odd
  2. 4
  3. 4 is Even Number
 

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

1 comments for C program to check odd or even without using modulus operator and division operator

Select Menu