In the previous blog we saw how to find the smallest among 3 three numbers. Now, we will see how to find if the given number is even or odd in c.

Conditional Statements:-

If condition:-

The if statement is used to examine a given condition and perform actions based on whether or not that condition is true. It's most commonly utilized in scenarios where we need to perform many operations for various situations. The if statement's syntax is seen below.

if(expression)

{

}

If-Else Condition:-

For a single condition, the if-else statement is used to conduct two operations. It's an enhancement to the if statement that allows us to conduct two different operations, one for the condition's correctness and the other for the condition's incorrectness. It is important to note that the if and else blocks cannot be run at the same time. The syntax is seen below.

if(expression)

{

}

else

{

}

To find whether a number is even or odd  in c.

#include <stdio.h>

int main()

{

int number;

scanf("%d",&number);

if(number%2==0)

{

    printf("It's even");

}

else

{

    printf("It's odd");

}

}

Example:-

If the number divided by 2 gives the remainder as 0 we will consider it as even .If the number divided by 2 gives the remainder as not 0 we consider it as odd .

6 when divided by 2 gives remainder as 0.So even.

7 when divided by 2 gives remainder as 1 .So odd

Algorithm:-

1.Start 

2.Include the header files  .

3.Declare a variable called number ,use scanf to get the input variable and use the format specifier as "%d".

4.If the number % 2 gives remainder as 0 .We print the statement as "It's even".

5.Else we print the statement as "It's odd".

6.Stop.

Screenshot:-

Code Screenshot:-



Output Screenshot:-


In, the next blog we will see how to find the greatest number among three .