PHP Compiler
<!DOCTYPE html> <html> <body> <?php $num = 19; $copyNum = $num; $digits = 0; $remainder = 0; $total = 0; // find number of digits in num variable while($copyNum != 0) { $digits++; $copyNum = floor($copyNum / 10); } $copyNum = $num; // slice the numbers from last digits while($copyNum != 0) { $remainder = $copyNum % 10; $total += pow($remainder, $digits); $copyNum = floor($copyNum / 10); } // result if($num == $total) echo "$num is an armstrong number"; else echo "$num is not an armstrong number"; ?> </body> </html>
OUTPUT
19 is not an armstrong number
×

Save as Private