# Re : Logic problem

• 01-31-2002
Wah
Re : Logic problem
Dear All,

I don't understand why the following function is wrong, can anyone tell me :

void check(int a) {
if (a / 2 == 1)
printf("a is odd\n");
else
printf("a is even\n");
}

Thanks a million.

Best regards,
Wah
• 01-31-2002
Nutshell
If you think about it carefully, a number / 2 == 1 is not working. What if the number is 11 ? 11 / 2 = 5. I think you wanna do somethin like this:
Code:

```checkEven( int a ) {   if ( a % 2 == 0 )       return 1;   else       return 0; }```
• 01-31-2002
Prelude
Code:

```void check(int a) {   if (a % 2 == 1)     printf("a is odd\n");   else     printf("a is even\n"); }```
-Prelude
• 01-31-2002
Nutshell
isn't that the same as my one lol?
• 01-31-2002
Prelude
Yes, but we posted at approximately the same time.

-Prelude
• 01-31-2002
Shiro
>void check(int a) {
>if (a / 2 == 1)
>printf("a is odd\n");
>else
>printf("a is even\n");
>}

A logical answer why this is wrong:

a / 2 = 1 if and only if a = 2

By the way, in your function 2 is odd. :-)