Finding multiples of a number (eg. 3) 
Interview question. For this we need the modulus operator: %
In computing, the modulo operation finds the remainder of division of one number by another.


//Remainder of $a divided by $b
//$a % $b
//echo (5 % 3)."\n"; // prints 2

So,

//main logic
if($number % 3 ==0)
//No remainder(nothing left after division).Number is multiple of 3.

[ view entry ] ( 1180 views )   |  print article

<<First <Back | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Next> Last>>



2024 By Angel Cool