What does a the "%" sign mean? as in "if (i % x==0)"?

This is a discussion on What does a the "%" sign mean? as in "if (i % x==0)"? within the C Programming forums, part of the General Programming Boards category; Code: if (i % x==0) My best guess is that it is some kind of logic statement, but I really ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    197

    What does a the "%" sign mean? as in "if (i % x==0)"?

    Code:
    if (i % x==0)
    My best guess is that it is some kind of logic statement, but I really have no idea.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Grab any basic C book and it will cover it. It's the modulus operator. It gives you the remainder of the left divided by the right. In this case, it produces the remainder of i divided by x.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Code:
    if (i % x==0)
    In this case, the test would be whether x is a factor of i. It would evaluate to true if x was a factor of i, otherwise false.

    You might want to change the format slightly to make it clearer.

    Code:
    if ( (i % x) == 0 )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sign ' is the same as \' ?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-23-2007, 07:32 AM
  2. My own itoa()
    By maxorator in forum C++ Programming
    Replies: 18
    Last Post: 10-15-2006, 12:49 PM

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