This program is to check whether the number provided by the user is even or odd. As you aware that even numbers are completely divisible by zero i;e they leave remainder zero when divided by two. On the other hand, odd numbers are not completely divisible by two. So, we can make use of the remainder operator(%) in c to check whether a number is odd or even.
C program to check if number is odd or even - Source code
/* Program to check whether the number
is even or odd using the modulus operator (%)
printf("Enter an integer: ");
// Modulus (%) returns remainder
if ( n%2 == 0 ) // returns true if remainder is 0
printf("%d is an even number", n);
printf("%d is an odd number", n);
Enter an integer: 6723
6723 is an odd number
Enter an integer: 4578
4578 is an even number
Modulus operator in C programming language, denoted by %, returns the remainder after the division operation. Here we have perform the modulus operator on the number provided by the user and checked whether it is equal to zero(n%2 == 0). The if statement is executed automatically if the expression inside it returns true value. Otherwise, the else statement is executed.