Home C Programming Episode 7: Odd or Even program

Episode 7: Odd or Even program

0
SHARE

Checking Odd Or Even Number

 

Hi there, Today I want to explain this stuff and make you think about the logic.Do you know Odd or even? Yes! Let say give me the series of even number. 2..4..6..8..10.. and what about odd series.. hmm.. 1..3..5..7.. blah blah. So, you know the even number are those number which is divisible by 2? Yes. Let say if any of odd number divisible by 2 then what happens? Its remainder will be 1. The difference between detecting odd or even is when the number is divisible by 2, the even number has remainder 0 whereas odd one has remainder 1. So, we got the formula that when mod of number is equal to 0 then its even else it is odd.

Try to think Logically, you will get to know how to code. If and else loop is used for condition specific statement. when ‘If’ condition statement is true then that block will execute or else ‘else’ block will execute.

 

#include <stdio.h>
#include <conio.h>

void main()
{
int n;
printf(“Enter the number: “);
scanf(“%d”,&n);

if(n%2==0)
{
printf(“\nNumber is Even”);
}

else
{
printf(“\nNumber is Odd”);
}

getch();
}

 

Output:

Enter the number: 4

Number is Even

 

Enter the number: 3

Number is Odd

LEAVE A REPLY

Please enter your comment!
Please enter your name here