PHP Compiler
<!DOCTYPE html> <html> <body> <?php $combination = 2; $num = array(4, 8); $limit = 500; echo "List of combinations of 4 and 8 upto 500: <br>"; // Iterate from 1 to limit for($i=1; $i<=$limit; $i++) { $copyNum = $i; $count = 0; $flag = 0; //Check each digit starting from last digit while($copyNum != 0) { $count++; $lastDigit = $copyNum % 10; for($j=0; $j<$combination; $j++) { if($num[$j] == $lastDigit) $flag++; } $copyNum = floor($copyNum / 10); } // result if($count == $flag) echo "$i "; } ?> </body> </html>
OUTPUT
List of combinations of 4 and 8 upto 500:
4 8 44 48 84 88 444 448 484 488
×

Save as Private