Why is 9 % 10 = 9?

This is a discussion on Why is 9 % 10 = 9? within the C Programming forums, part of the General Programming Boards category; 9 mod 10 gives 9, but why? 9 / 10 = 0, so the remainder should also be zero shouldn't ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    20

    Why is 9 % 10 = 9?

    9 mod 10 gives 9, but why?

    9 / 10 = 0, so the remainder should also be zero shouldn't it?

    This works the same for 0-9, but why?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Because 10 doesn't go into 9 ... giving you 0 with a remainder of 9.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Code:
    divident = divisor*quotent + remainer <==> remainer = divident - divisor*quotent
    Simple...
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

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