C program to check whether a number is even or odd – In this article, we will discuss the method to check whether a number is even or odd in C programming.
Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.
The method used in this piece is as follows:
- Using Standard Method
As well all know, an even number is a number which is divisible by 2 and does not leave behind a remainder.
However, an odd number is a number is a number which isn’t divisible by 2 and leaves behind a remainder.
As we can see in the image uploaded above, you need to enter a value which you wanna check whether it is even or odd.
The number which is mentioned is 7.
It is evident that 7 is an odd number.
Thus, the same to do in C programming is as follows:
Using Standard Method
1)Read the entered number and store in the variable n using scanf function.
2)If n is divisible by 2 then print “it is an even number”, otherwise print “it is an odd number”.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include<stdio.h> #include<conio.h> int main() { int n; printf("enter n value:\n"); scanf("%d",&n); if(n%2==0) printf("it is an even number\n"); else printf("it is an odd number\n"); } |
1 2 3 |
enter n value: 7 it is an odd number |