Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining even/odd numbers (integers)?

Tags:

android

math

I feel stupid asking such a simple question, but is there an easy way to determine whether an Integer is even or odd?

like image 817
Snailer Avatar asked Sep 29 '10 21:09

Snailer


People also ask

How do you determine even and odd numbers?

Definition 1: “Even numbers are those numbers which are divisible by 2 and odd numbers which are not divisible by two”. Definition 2: “Even numbers are those which when divided by 2 leaves no remainder or as 0 and Odd numbers are those numbers which when divided by 2 leaves a remainder of 1”.

What is odd integers and even integers?

If the units digit (or ones digit) is 1,3, 5, 7, or 9, then the number is called an odd number, and if the units digit is 0, 2, 4, 6, or 8, then the number is called an even number. Thus, the set of integers can be partitioned into two sets based on parity: the set of even (or parity 0) integers.

How do you determine an odd number?

An odd number is a number that is not divisible by 2. The remainder in the case of an odd number is always “1”. 11 is an odd number.

What is the best way to check if an integer is even or odd?

A number is even if, when divided by two, the remainder is 0. A number is odd if, when divided by 2, the remainder is 1.


1 Answers

if ((n % 2) == 0) {
    // number is even
}

else {
    // number is odd
}
like image 86
Richard Fearn Avatar answered Sep 28 '22 07:09

Richard Fearn