Checking numbers for multiples

Discussion in 'iOS Programming' started by HarryWorksInc, Aug 7, 2010.

  1. macrumors regular

    Joined:
    Feb 21, 2010
    #1
    Is there anyway to check for multiples of a certain number? I would do something like:
    HTML:
    if (num==0) {
            //code
    } else if (num==5) {
            //code
    } else if (num==10) {
            //code
    }
    But these numbers will go into the thousands so it would be very complicated to do it that way.

    Thanks
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    Look up the modulo operator in C, represented by the % symbol.
    Code:
    if ( (num % 5) == 0 ) ... 
     
  3. thread starter macrumors regular

    Joined:
    Feb 21, 2010

Share This Page