C Program to Check Whether a Number is Even or Odd using If-else Statement
ADVERTISEMENTS
C program to check whether a number is even or odd using if-else statement. In this article, you will learn how to make a C program to check whether a number is even or odd using if-else statement.
What is even odd numbers?
If any integer number is divided by 2 and its reminder equals zero then it is an even number and the remainder is greater than zero then it is an odd number.
Samples of Even & Odd Numbers
Even Numbers: 0, 2, 4, 6, ...
Odd Numbers: 1, 3, 5, 7, ...
Source Code
// C Program to Check Whether a Number is Even or Odd using If-else Statement
#include <stdio.h>
int main() {
int x;
printf ("Enter an integer number to check ::\n");
scanf ("%d", &x);
if (x % 2 == 0) {
printf ("The input number is even.\n");
} else {
printf ("The input number is odd.\n");
}
return 0;
}
Output
Enter an integer number to check ::
7
The input number is odd.
C Program to Check Whether a Number is Even or Odd using Conditional Operator
// C Program to Check Whether a Number is Even or Odd using Conditional Operator
#include <stdio.h>
int main() {
int x;
printf ("Enter an integer number to check ::\n");
scanf ("%d", &x);
x = x % 2 == 0 ? 1 : 0;
if (x) {
printf ("The input number is even.\n");
} else {
printf ("The input number is odd.\n");
}
return 0;
}
Output
Enter an integer number to check ::
6
The input number is even.