# 15 – C Program to check if a number is even or odd

## C program to check if a number is even or odd

In programming it is easy to find if number is even or odd.

we need to divide it by 2 and if the reminder 0 then it’s even else it’s odd

In C programming we have two methods:

1. With IF-ELSE
2. With ternary operator

### Logic to check if a number is even or odd in C

#### With IF-ELSE

`#include<stdio.h>//itvoyagers.inint main(){    int x;    printf("Enter any number : ");    scanf("%d",&x);    if(x % 2 == 0)    {        printf("n %d is Even",x);    }    else    {        printf("n %d is Odd",x);    }    return 0;}`

Output :

Enter any number : -9

-9 is Odd

Enter any number : 8

8 is Odd

#### With Ternary operator

```#include<stdio.h>
//itvoyagers.in
int main()
{
int x;
printf("Enter any number : ");
scanf("%d",&x);
(x % 2 == 0)? printf("n %d is Even",x) : printf("n %d is Odd",x);
return 0;
}```

Output :

Enter any number : 7

7 is Odd

Enter any number : 8

8 is Odd

### Connect with us on following platforms

We are aiming to explain all concepts of C in easiest terms as possible.
ITVoyagers
Author