Please Help

G

Giff

Solve this Question
Write a Program to find a number is even or odd?

LOL, no shame at all!
Com'on, use your brain if you have one! How would you find out whether a
number is even or odd?
 
C

ctrucza

Solve this Question
Write a Program to find a number is even or odd?

how about this:

bool is_even(int n)
{
return ( (n == 0) || (n == 2) || (n == 4) || ... || (n ==
2*K) ); // for a carefully chosen value of K
}

Of course this will work correctly only for positive integers smaller
or equal than 2*K.
Extending it to work for negative numbers and other values of K is
fairly trivial.
 
G

Giff

ctrucza said:
how about this:

bool is_even(int n)
{
return ( (n == 0) || (n == 2) || (n == 4) || ... || (n ==
2*K) ); // for a carefully chosen value of K
}

LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please help 7
Can't solve problems! please Help 0
C coding a rotate function (help me pleasee) 1
Please, help me. 1
Please help 2
Please help me!!! 3
Odd or Even with Modulo 6
Please Help 2

Members online

Forum statistics

Threads
474,167
Messages
2,570,913
Members
47,455
Latest member
Delilah Code

Latest Threads

Top