Thread: Modulus

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    2

    Modulus

    Hi, I have no idea how to separate numbers using modulus. If the user enters "12345", the program would have to output 1..2..3..4..5.
    Please help :-)

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    When you do "number modulo 10", you get the right-most( aka least significant ) digit of that number. With that in mind, you can find all of the digits with some simple division and comparison.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Apr 2017
    Posts
    80
    Rather than using modulus, surely treating the number as a string/array and simply accessing each element/digit by their index, number[0], number[1], etc. would be better/easier?
    Last edited by BpB; 04-24-2017 at 12:27 AM.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Yes, if the number was already available in string form them it would be easier and more sensible to do it that way. But since @Caiz mentioned modulus, I assumed they had to work with integers specifically.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modulus Division?
    By Shamshir in forum C Programming
    Replies: 5
    Last Post: 03-09-2011, 09:03 AM
  2. %(Modulus)
    By cuo741 in forum C Programming
    Replies: 19
    Last Post: 05-14-2010, 08:50 AM
  3. modulus
    By nicknack in forum C Programming
    Replies: 7
    Last Post: 12-15-2007, 09:45 AM
  4. Modulus question!
    By bobthebullet990 in forum C Programming
    Replies: 12
    Last Post: 01-05-2007, 08:54 AM
  5. Help with Modulus
    By boontune in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 10:26 AM

Tags for this Thread