A challenge:
goal: write a code that with minimal code possible.
Task: determine the character input wheter is an odd or even number!!!
ie:
Input Output expected
1 Odd
2 even
etc...
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
Posted: Thu Jan 13, 2005 9:27 am
Sounds like a school project to me but all you need to do is receive a char and look at the last bit to determine if it is even (clear) or odd (set). You might want to determine if the char falls within the 0x30-0x39 range to ensure that it is a digit. If you need more than a single digit number, then you can just look at the last digit.
jbmiller Guest
odd vs even
Posted: Thu Jan 13, 2005 5:31 pm
I've always used the old standy...
if (x/2)=int(x/2) then even else odd...
..now you'll have to convert to C code but it has worked for me since the mid70's...
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum