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

# 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 <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:

• 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

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.