Re: =?WINDOWS-1252?Q?Stupid_newbie_que stion_=97_determine_if_intege r?= is even or odd
Re: =?WINDOWS-1252?Q?Stupid_newbie_que stion_=97_determine_if_intege r?= is even or odd
- Subject: Re: =?WINDOWS-1252?Q?Stupid_newbie_que stion_=97_determine_if_intege r?= is even or odd
- From: Andrew Zamler-Carhart <email@hidden>
- Date: Tue, 13 Aug 2002 15:12:48 -0700
Jan,
Use the "mod" operator (%). For example, a % b gives you the remainder
of dividing a by b. If you divide an integer by 2 and the remainder is
0, the number is even. If the remainder is 1, the number is odd. For
example:
+ (BOOL) isEven: (int) n {
return n % 2 == 0;
}
+ (BOOL) isOdd: (int) n {
return n % 2 == 1;
}
Andrew
On Tuesday, August 13, 2002, at 02:57 PM, Jan Van Boghout wrote:
Hi everybody,
I feel kind of embarrassed to ask this, but I looked for hours and
still don't have a solution.
How do you determine whether an integer is odd or even? I tried messing
around with the fact that an odd integer divided by 2 would not be able
to be an integer again, but my attempts were unsuccesful :\ Any help
is welcome!
Thanks,
Jan VB
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.