loader image

Armstrong number in PHP

Aim: Write a PHP program to check whether a given number is Armstrong or not.

Check Armstrong Number of three digits

<html>

<body>
    <h2>Enter the Number</h2><br>
    <form action="" method="post">
        <input type="text" name="number" />
        <input type="submit" />
    </form>
</body>

</html>
<?php
if ($_POST) {
    $number = $_POST['number'];
    $temp = $number;
    $sum = 0;
    while ($temp != 0) {
        $rem = $temp % 10;
        $sum = $sum + ($rem * $rem * $rem);
        $temp = $temp / 10;
    }
    if ($number == $sum)
        echo $sum." is Armstrong Number";

    else

        echo $sum." is Not an Armstrong Number";
}
?>
Output
perfect js
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top