Program to find out odd and even number

Program to find out odd and even number


#include<stdio.h>
void main()
{
int number;
printf("Enter number to be checked: ");
scanf("%d",&number);
if(number%2==0)
{
printf("Even Number");
}
else
{
printf("Odd Number");
}
}

Output:






Explanation:

We have taken a number from user using scanf() function.
We have divided number by 2 and found out remainder using Modulo(%) operator.
We know that all even numbers when divided by 2, remainder is 0.
So, we have used if else conditions stating that if number divided by 2 remainder is 0 then print even number else print odd number.





Note: 

  • In scanf() function we use address of variable to store value of inputted number. 
  • Syntax of if else conditions.

No comments:

Post a Comment