Checking if a number is even or odd in C
To study the parity of a number you just have to check whether or not it is a multiple of the number 2.Even numbers are the numbers that end in
{0, 2 , 4, 6, 8, 10, 12,..., n*2} = {2n; n is a natural or relative number}.
Odd numbers are numbers that end in
1, 3 , 5, 7, 9, 11, 13,..., n*2+1= {2n+1; n is a natural number or relative}.
A number pair is any number of which the rest of the Division on 2 is equal to 0. They are also said to be multiples of 2.
A number odd is any number of which the rest of the Division on 2 is equal to 1.
Even numbers are split into two equal parts:
3 + 3 = 6
4 + 4 = 8
7 + 7 = 14
Odd numbers are not split into two equal parts:
3 = 1 + 2
7 = 3 + 4
41 = 40 + 1
The square of even numbers is even example:
0² = 0
2² = 4
4² = 16
6² = 36
The square of odd numbers is odd example:
1² = 1
3² = 9
5² = 25
7² = 49
Note:
Any prime number is an odd number except the number 2.Example
#include< stdio.h>#include< stdlib.h>
main()
{
int number;
if(number%2==0)
printf("%d is an even number\n",number);
else
printf("%d is not an odd number\n",number);
system("pause");
}