How would I write a function that determines if a number is a multiple of another number.
ex. (is 147 a multiple of 7?)
How would I write a function that determines if a number is a multiple of another number.
ex. (is 147 a multiple of 7?)
Use the modulus operator (%) to calculate the remainder. If a % b is zero then a is a multiple of b.
Last edited by Golf7; 10-10-2013 at 05:04 PM.
and, if you don't want to use the modulus operator (which is sometimes the case in homework exercises of this nature) use division, multiplication, and subtraction.
You can use this for the present task:Code:int quotient,number1,number2; quotient=number1/number2; if(( quotient*number2 ) == number1) printf("it is a multiple");else printf("it is not a multiple");
Last edited by Suhasa010; 10-13-2013 at 11:24 AM.