Splitting integer

This is a discussion on Splitting integer within the C++ Programming forums, part of the General Programming Boards category; If I input a 5 digit number, how would I split it up into it's individual digits? I am told ...

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    Splitting integer

    If I input a 5 digit number, how would I split it up into it's individual digits? I am told that I must use the modulus and division operators however I am still new to the modulus operator and am not quite sure how to go about this.

    eg.
    Input --> 12321
    Splits into 1 2 3 2 1

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Code:
    int x, y;
    x = 236;
    y = x % 10;  // y contains 6, modulus operator
    x = x / 10;  // x contains 23, standard integer division
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21