Header Ads

09 - WAP to Print Odd or Even without using '%' Operator in C


This program Prints the Odd or Even for the given Number without using "%" operator. But by using Bitwise "Ternary" (&) Operator.

//to check odd or even by bitwise & operator
#include 
int main ()
{
    int num;
    printf("Enter a Number to be check'ed : ");
    scanf("%d", &num);
    //ternary operator to check even or odd
    ( num & 1 ) ? printf("Number is Odd.\n") : printf("Number is Even.\n");
   return 0;
}

Program Output: 

No comments