C programming can be a fun way to get our logical instincts going. As it uses simple language to let the compiler formulate results, there are a variety of easy programs that can be used at a beginner level to form the basis of future advancements. Numbers are vital, and so trying the program to come up with a way to distinguish between even and odd numbers can be interesting. It can be done through a few approaches, such as by using modulus operator, bitwise operator and conditional operator. Using these operators can help define and store values for further operations and commands.

## Using Conditional Operators in C programming

The conditional operator == is used to check if any of the two operands defined are equal. The condition becomes true when the desired operands are equal.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include int main() { int n; printf("Input an integer\n"); scanf("%d", &n); n%2 == 0 ? printf("Even\n") : printf("Odd\n"); return 0; } |

1 2 3 4 |
Input an integer: 8 8 is even. Input an integer: -3 -3 is odd. |

### Using Modulus Operator in C programming

Modulus operators act as a way to divide and then come up with a solution. The operator % is designed to divide the numbers into half and find the result, equal to the requested command. There is also a conditional operator to ensure that the values that come can be equated to the values of being even or odd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include int main() { int n; printf("Enter an integer\n"); scanf("%d", &n); if (n%2 == 0) printf("Even\n"); else printf("Odd\n"); return 0; } |

1 2 3 4 |
Enter an integer: 6 6 is even. Enter an integer: -5 -5 is odd. |

### Using Bitwise Operator

Bits are usually defined as either 0 or 1. And the only values they can tell is either a number is 1 or 0. Therefore, using the AND command to see if any of the numbers is even or odd, may usually tell the result of odd numbers as being 1. It can be rather complicated at times and needs a grip over the way bits work.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* Program to check if number is even or odd * using bitwise operator */ #include int main() { int n; printf("Enter an integer: "); scanf("%d",&n); if ( n & 1) printf("%d is an odd number", n); else printf("%d is an even number", n); return 0; } |

1 2 3 4 |
Enter an integer: 77 77 is odd. Enter an integer: 44 44 is even. |

One of the hardest ways in using bitwise operator is the way conditions work in it. The AND command is vital for compiler to understand if both operands are non-zero or not. If they are , the condition can be deemed true. Likewise, OR operators are also use the same conditions to come up with a true non-zero operand.