Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

  • 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.


Program #1: write a c program to check a Number is even or odd without using modulus and division operators in c programming.

  1. #include
  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:



  • 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)

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

  1. #include
  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)
  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
 


This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

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

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×