DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    danny herrera Guest

    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

  2. #2
    naomi Guest

    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links