Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Even Odd Checker using C Programming

Problem Statement

In this program we will code a basic program to check whether a number is even or odd.

We can do this with the help of

1.    Conditional Statement – if statement

2.    Predefined C function – printf()

Code

#include

void evodcheck(int num)

{

        if(num % 2==0)

        {

                 printf("Given number %d is Even.", num);

        }

        else

        {

                 printf("Given number %d is Odd.", num);

        }

}

int main()

{

        int n;

        printf("Enter a number to check : \n");

        scanf("%d", &n);

        evodcheck(n);

        return 0;

}

Output

Enter a number to check : 45
Given number 45 is Odd.

Explanation 

To check whether a number is even or odd, we need % (mod) operator. This mod operator is used to find the remainder for a division operation. For given two numbers, say a & b, mod operator can be used to check if one number divides other number or not. If a%b is 0, then b divides a.

Post a Comment

0 Comments