Monday, 4 August 2014

C program to check Odd or Even

Advertisement

In mathematics, in decimal number system even numbers are divisible by 2 while odd are not so we can use modulus operator(%) which returns remainder, For example 4%3 gives 1 ( remainder when four is divided by three). Even numbers are of the form 2*p and odd are of the form (2*p+1) where p is is an integer.

C program to check odd or even using modulus operator

#include
 
main()
{
int n;
 
printf("Enter an integer\n");
scanf("%d",&n);
 
if ( n%2 == 0 )
printf("Even\n");
else
printf("Odd\n");
 
return 0;
}


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)