Thread: How to Extract Numbers

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    79

    How to Extract Numbers

    I've been trying to figure out how to extract numbers from an integer you insert via scanf. My whole assignment is to find out how many 0's-9's are in an inserted integer (aka how many of each is there in 129038018 and it prints out Num of 0's = 2, Num of 1's = 2, etc.) But, again, my problem is finding out how to extract the numbers in order to find them... And doing so without using arrays, I haven't learned how to use those yet.

  2. #2
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Get the input as an int. Modular divide(%) by 10 to get the least significant digit, if it's one you're concerned with, increment a counter, whether it is or not divide(/=) by 10. Do so until the number is 0.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    I knew I could use that but I don't know how to set up a loop that keeps doing that until there are no more ints to count. Can I use a for loop for this? Please help.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to reverse numbers with sizeof operator
    By JoelearningC in forum C Programming
    Replies: 13
    Last Post: 03-09-2008, 11:53 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM