Become Our Fan on Social Sites!

Facebook Twitter

Google+ RSS YouTube

Thursday, 26 September 2013

C program for to check odd or even number

Even Number : If we divide number by 2 and remainder is 0 is called Even Number.

Odd Number : If we divide number by 2 and remainder is 1 then that number is called Odd Number.  


1) Using Modulus Operator


#include<stdio.h>

int main()
{
    int no;

    printf("Enter No : ");
    scanf("%d",&no);

    if( no % 2 == 0 )
        printf("Even Number");
    else
        printf("Odd Number");
    
    return 0;
}


2) Using Conditional Operator


#include<stdio.h>

int main()
{
    int no;

    printf("Enter No : ");
    scanf("%d",&no);

    no % 2 == 0 ? printf("Even Number") : printf("Odd Number");

    return 0;
}


3) Using Bit-wise Operator

#include<stdio.h>



int main()

{

    int no;



    printf("Enter No : ");

    scanf("%d",&no);



    if (  (no & 1)  == 0 )

        printf("Even Number");

    else

        printf("Odd Number");



    return 0;

}


0 comments :

Post a Comment