answersLogoWhite

0


Best Answer

The following simply uses the definition of "odd" and "even". Do an integer division by 2. If it is divisible (no remainder), it is even. Else, it is odd. Here is some sample code in Java:

System.out.println(myNumber % 2 == 0 ? "It is even" : "It is odd");

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

The way to do this is to test on the modulo (remainder) of dividing the number by 2.

For example:

4/2 = 2, with 0 remainder. So, 4 modulo 2 = 0. This is for an even number.
5/2 = 2, with 1 remainder. So, 5 modulo 2 = 1. This is for an odd number.

The modulo for any integer divided by 2 is either 1 or 0. All odd numbers will return a 1 modulo, and all even numbers return a 0 modulo.

So, your test becomes:
If the modulo of the input number is 1, then the input number is odd. Otherwise it is even.

The actual code to do this varies depending on which programming or scripting language you are going to use. For example, in Perl:

print ($ARGV[0] % 2) ? "Odd\n" : "Even\n";

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

To find out if number is Odd or Even in C Programming language you could use % operator.

It returns reminder left after division of two passed numbers.

For example:

0 % 2 = 0

4 % 3 = 1

5 % 1 = 0

To check if number is Odd or Even you need to divide it by 2.

Here is small program:

#include

int main() {

int num;

printf("Enter number: ");

scanf("%d", &num);

if (num % 2 == 0) {

printf("Number is Even.\n");

} else {

printf("Number is Odd.\n");

}

return 0;

}

Testing:

Enter number: 2

Number is Even.

Enter number: 3

Number is Odd.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

// To check if a number is even, check to see if it is evenly divisible by 2.

// If you have no remainder, then it's even. Otherwise it's odd.

public static boolean isEven(int n) {

return (n % 2) == 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

#include<stdoio.h>

#include<conio.h>

void main()

{

int a;

printf("Enter the number");

scanf("%d",&a);

if(a%2==0)

{

print("number is even");

}

else

{

printf("number id odd");

}

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: To find whether a number is odd or even?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How Do You Find The Square Root of Odd Numbers?

The procedure is the same whether the number is even or odd. There is no separate procedure for odd numbers.


Is 50 odd?

No. All number ending with 0,2,4,6,8 is even and numbers with 1,3,5,7,9 endings are odd. Since 50 has an ending of 0, it is even. Another way to find whether or not a number is even or odd, you just have to divide that number by 2. If the answer is a whole number, it is even.


What is the sum of an odd number of odd numbers?

It is a negative number. The answer is the same whether there is an odd or even number of addends.


How can you tell whether the product of an addition problem will be odd or even?

whenever you add an even number the answer will be the same (odd/even) as the other number


Test whether a number is even or odd?

An even number can be divided by 2 evenly. An odd number will have a remainder of 1 when divided by 2.


How can your tell whether a number is even or odd?

An even number can be divided by 2 evenly. An odd number will have a remainder of 1 when divided by 2.


What is the sum of an odd number of negative addends?

It is a negative number. The answer is the same whether there is an odd or even number of addends.


How can you use the prime factorization of a number to determine whether the number is even or odd?

If the factorization includes the number 2, it's even. If not, it's odd.


How do you draw a Flowchart to find whether the given number is odd or even using counter?

first we write start and then read number and after that check the number is totaly divide by 2 or not if number is totally divide by 2 then number is even else number is odd.


What sign is the rational number if it is even?

The sign of a rational number does not depend on whether it is odd or even.


Why is it when you multiple a number by two always an even number?

It's just one of those laws of maths. It can be used as an indication to whether the answer could be right. It's similar to even + even = even Even + odd = odd Odd + odd = even


Test whether a number is even or add?

A number is even when you can divide it by 2. Ex: 44/2=22 (even) 18436/2=8218 (even) 165/2=82.5 (odd)