Subscribe to:
Post Comments (Atom)
CodeShikhi - The World for Programmers, প্রোগ্রামিং,Learn Programming,Learn Javascirpt | C | C++ | Python | OOP,Learn Programming in Bangla,Bangla Programming Tutorial,Leetcode Problem Solution,BEE Problem Solution,C Programming in Bangla,C in Bangla,Javascript tutorials,C Programming Bangla Tutorial, URI Online Judge Solution in C C++ Python,JavaScript Full Tutorials , OOP Tutorial in C++, Object Oriented Programming in C++,Learn OOP in C++,C Programming Exercise,C Programming Example with Code
#include<stdio.h>
int main()
{
int i;
printf("Enter a Number\n");
scanf("%d",&i);
if(i%2==0)
{
printf("The number %d is Even",i);
}
else
{
printf("The number %d is Odd",i);
}
printf("\n");
}
Enter a Number 5 The number 5 is Odd
Here we declared an integer 'i'.
Then we took the input from user using scanf statement.
As we know modulus operator is used to return the reminder of two values as(10%3=1, 12%2=0).
So if you do modulus with 2 then the reminder would be 'zero' for Even numbers and '1' for Odd numbers.
If we divide 'i' with '2' using mod operator then depending upon condition the respective 'printf' will be executed.
Next Post:
How To Print all the Odd Numbers till N in C Programming | C Programming Examples - 10
Previous Post:
0 Response to How To Print Even or Odd Numbers in C Programming | C Programming Examples - 9
Post a Comment