This particular section is of If-else conditionals it helps the user to check different
conditions like in the below program we are going to check whether the entered
number is even or odd.
As we all know even number is divisible by 2 and odd number is not divisible by 2
so, we have used the remainder logic that if entered number is divided by 2 and
remainder comes out be 0 then, it's an even otherwise odd.
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i,m=1;
printf("Enter any number: ");
scanf("%d",&n);
if(n%2==0)
{
printf("%d is an even number",n);
}
else
{
printf("%d is an odd number",n);
}
}
Output:
Output when if part is true. Output when if part is false.
Post a Comment