Sunday 19 October 2014

C Program for Given Number is Even or Odd using Bit-Wise Operators

Program:

#include<stdio.h>  //header file
#include<conio.h>  //header file
int odd(int); // funtion proto type
void main( )
{ //main function begins
          int n;
          printf("\nEnter a Number:");
          scanf("%d",&n);
          if(odd(n))
          {
                printf("\n Given Number is ODD");
           }
           else
           {
                printf("\n Given Number is EVEN");
            }
}//main function ends
int odd(int n)
{
           if(n&1)
           {
                      return 1;
            }
            else
            {
                       return 0;
             }
}

Input/Output:

Enter a Number: 5

Given Number is ODD







0 comments:

Post a Comment