divisble?

This is a discussion on divisble? within the C Programming forums, part of the General Programming Boards category; I'm having trouble understanding or determining if a number is divisible by 10. Is 70 divisible by 10? How exactly ...

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335

    divisble?

    I'm having trouble understanding or determining if a number is divisible by 10. Is 70 divisible by 10? How exactly is it worked out? I've tried a few divide calculations but it doesn't make sense as to why 10 is divisible.

    I'm assuming the following:

    70/10 = 7. There is no reminders therefore it's divisible by 10?..
    Last edited by Axel; 09-14-2006 at 09:35 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    The % operator returns zero if the lhs is evenly divisible by the rhs.

    [edit]
    Code:
    #include <stdio.h>
    
    int divisible(int x, int y)
    {
       return x % y == 0;
    }
    
    int main()
    {
       int x = 70, y = 10;
       printf("divisible(%d,%d) = %d\n", x, y, divisible(x,y));
       x = 42;
       printf("divisible(%d,%d) = %d\n", x, y, divisible(x,y));
       return 0;         
    }
    
    /* my output
    divisible(70,10) = 1
    divisible(42,10) = 0
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Basic math.
    Code:
    x = 70 / 10;
    y = x * 10;
    
    if( y == 70 )
        printf( "Yay!" );
    else
        printf( "So sad!" );
    Quzah.
    Hope is the first step on the road to disappointment.

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