Thread: Separating an Integer into digits

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Separating an Integer into digits

    Hi,
    I am trying to discover how to find the individual digits within a number. For example, 4653 is made up from 4, 6, 5, then 3. I have been trying to work this out but have got stuck. I am sure there is a simple procedure which may have a proper name that I am unaware of so I am struggling to find information on how to do it.
    Any pointers would be very gratefully received. Thanks

  2. #2
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Code:
    digit = x % 10 + '0';
    x /= 10;    /* next digit */
    .sect signature

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Talking

    Thanks ggs, I have got it working now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM