belongs to collection: PHP basic programs with examples
Write a PHP program to check if a number is an Armstrong number or not
PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..
<?php function armstrong_number($num) { $sl = strlen($num); $sum = 0; $num = (string)$num; for ($i = 0; $i < $sl; $i++) { $sum = $sum + pow((string)$num{$i},$sl); } if ((string)$sum == (string)$num) { return "True"; } else { return "False"; } } echo "Is 371 Armstrong number? ".armstrong_number(371); echo "<br>Is 21 Armstrong number? ".armstrong_number(8208); echo "<br>Is 4587 Armstrong number? ".armstrong_number(10);"\n";
Result:
Is 371 Armstrong number? TrueIs 21 Armstrong number? TrueIs 4587 Armstrong number? False
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..
Result:
need an explanation for this answer? contact us directly to get an explanation for this answer