Write a C program to check whether a number is even or odd using if else.
Example:
Input :
Input number: 10
Output:
10 is even number
/**
* C program to check even or odd number
*/
#include <stdio.h>
int main()
{
int num;
/* Input number from user */
printf("Enter any number to check even or odd: ");
scanf("%d", &num);
/* Check if the number is divisible by 2 then it is even */
if(num % 2 == 0)
{
/* num % 2 is 0 */
printf("Number is Even.");
}
else
{
/* num % 2 is 1 */
printf("Number is Odd.");
}
return 0;
}
/*
Output :
Enter any number to check even or odd: 228
Number is Even.
Enter any number to check even or odd: 289
Number is Odd.
*/