Write a C program to check whether a given number (integer) is Even or Odd

Write a C program to check whether a given number (integer) is Even or Odd

In this post, we will cover the topics How to check whether a given number is even or odd in c language, c code for checking a number is even or odd, how to write a program for checking a input number is even or odd.



In the following code, we have used the modulus operator( %) inside the if statement.

Use of modulus operator

The modulas operator is used to find the remainder, in the following case we have used number%2 
it means whatever value of number will be divided by 2 and will give the remainder value.
in this case if number%2==0 then it means the number is divisible by 2 and it will print the number is odd. In else cases, it will print the number is odd.
If you don't know how to write the rest of the portion you can see this posts
#include <stdio.h>
int main()
{
int number;
scanf("%d", &number); /*An integer number will be taken from the test case */
if(number%2==0)
printf("%d is even.", number);
else
printf("%d is odd.", number);
}

         Input                                          Output
51
 51 is odd.





If you have any questions or quarry feel free to write down In comment section.
happy coding



Post a Comment

0 Comments