Thread: Expressions with C89 (Noob)

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    1

    Expressions with C89 (Noob)

    Hi all!

    Programming beginner here just reading a book by K. N. King called c programming a modern approach which is an excellent book, but i am stuck trying to understand what is going on here.

    I am trying to understand why with the C89 standard that:

    -9/7 is -1 -9%7 is -2
    or
    -9/7 is -2 -9%7 is 5

    Any explanation of this would be greatly appreciated
    Last edited by vulcan_; 06-03-2017 at 01:09 PM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Modulo is defined as follows.

    -9/7 * 7 + -9%7 has to equal -9

    This would be true for any set of operands a and b, it so happens that here a=-9 and b=7

    (-1) * 7 + (-2)

    (-7) - 2 = -9

    (-9/7 will never be -2 I don't know where you got that from, btw)
    Last edited by whiteflags; 06-03-2017 at 01:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expressions and outputs
    By telmo_d in forum C Programming
    Replies: 7
    Last Post: 06-13-2015, 12:19 PM
  2. Are these expressions = ?
    By asdfghj in forum C Programming
    Replies: 2
    Last Post: 04-18-2011, 10:41 AM
  3. Expressions
    By DMEngOba in forum C Programming
    Replies: 2
    Last Post: 05-25-2009, 03:56 PM
  4. Regular Expressions
    By stormbringer in forum Windows Programming
    Replies: 3
    Last Post: 03-27-2003, 09:35 AM
  5. expressions
    By lizardking3 in forum Tech Board
    Replies: 5
    Last Post: 02-18-2003, 10:41 AM

Tags for this Thread