CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Hey Guys a trivial question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

Hey Guys a trivial question
PostPosted: Thu Jan 13, 2005 9:12 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Jan 13, 2005 9:27 am     Reply with quote

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
PostPosted: Thu Jan 13, 2005 5:31 pm     Reply with quote

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...

Jay
Guest








PostPosted: Fri Jan 14, 2005 1:51 am     Reply with quote

if (a & 1) {
..........
}

Or in assambly:
btfsc a,0
.........
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group