How to find whether a number Armstrong or not using PHP
How To Find Whether A Number Armstrong Or Not Using PHP – An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php if(isset($_POST['submit'])) { $number = $_POST['num']; // get the number entered by user $temp = $number; $sum = 0; while($temp != 0 ) { $remainder = $temp % 10; //find reminder $sum = $sum + ( $remainder * $remainder * $remainder ); $temp = $temp / 10; } if( $number == $sum ) { echo "$number is an Armstrong Number"; }else { echo "$number is not an Armstrong Number"; } } ?> <!DOCTYPE html> <html> <head> <title>Whether a number Armstrong or not</title> </head> <body> <form name="armstrong" action="" method="post"> Number :<input type="text" name="num" value="" required=""><br> <input type="submit" value="Submit" name="submit"> </form> </body> </html> |