function isArmstrong($num) {
$sum = 0;
$temp = $num;
while ($temp != 0) {
$digit = $temp % 10;
$sum += $digit ** strlen((string)$num);
$temp = (int)($temp / 10);
}
return $sum == $num;
}
// Example usage:
$number = 153;
if (isArmstrong($number)) {
echo "$number is an Armstrong number.";
} else {
echo "$number is not an Armstrong number.";
}
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Subscribe
Login
0 Comments
Oldest