-
single out digits from a three digit number
how would i about determining whether the digits in a three digit number are
odd or even. i thought this code might work but im not sure.
num == 123
digit1 == num % 10 = 3
num == num / 10 = 12
digit2 == num % 10 = 2
num == num / 10 = 1
digit3 == num % 10 = 1
-
Re: single out digits from a three digit number
"danny herrera" <danny.herrera4@gte.net> wrote:
>
>how would i about determining whether the digits in a three digit number
are
>odd or even. i thought this code might work but im not sure.
>
>num == 123
>digit1 == num % 10 = 3
>num == num / 10 = 12
>digit2 == num % 10 = 2
>num == num / 10 = 1
>digit3 == num % 10 = 1
num = 123
digit1 = ((num % 2) == 1)
num = num / 10
digit2 = ((num % 2) == 1)
num = num / 10
digit3 = ((num % 2) == 1)
digit1,2 and 3 are boolean and true if the digit is odd
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks