Check a number is even or odd in C
if else - Question 1
In this question, we will see how to check if a number is an even or odd number in C programming using the if else statement. To know more about if else statement click on the if else statement lesson.
Q1) Write a program in C to input a number and check it is an even or odd number. An even number is a number which is divisible by 2 and odd number is a number which is not divisible by 2.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int n;
printf("Enter a number ");
scanf("%d",&n);
if(n%2==0)
{
printf("Even Number");
}
else
{
printf("Odd Number");
}
return 0;
}
Output
Enter a number 18 Even Number