armstrong number program in php

Today, We want to share with you armstrong number program in php.In this post we will show you armstrong number between 100 to 999 in PHP program, hear for list of armstrong numbers we will give you demo and example for implement.In this post, we will learn about Check Armstrong Number in GO Program with an example.

Armstrong Number Program in PHP With Example

what is armstrong number?

A simple defination of the Armstrong number is a number that is the all the data sum of its own digits each raised to the power of the total number of digits is equal to the number itself. for example bellow

Read Also:  Laravel 6 Eloquent WHERE Like query Example

Example 1: index.php

<html>
    <head>
        <title>Armstrong number in PHP - www.pakainfo.com</title>
    </head>
    <body>  
        <form method="post">  
            Enter a number:  
            <input type="number" name="number">  
            <input type="submit" value="Submit">
        </form>  
    </body>  
</html>
 
<?php

 if($_POST)  
 {   
  
  $number = $_POST['number'];
    
  $a = $number;  
  $sum  = 0;
  
  
  while( $a != 0 )
  {  
   $rem   = $a % 10; 
   $sum   = $sum + ( $rem * $rem * $rem );
   $a   = $a / 10;  
  }  

  if( $number == $sum )  
  {  
   echo "Yes $number an Armstrong Number";  
  }else  
  {  
   echo "$number is not an Armstrong Number";  
  }  
 }

PHP Code:

Example 2:

<?php

$num=585;
$sum=0;
$temp=$num;
while($temp!=0)
{
$rem=$temp%10;
$sum=$sum+$rem*$rem*$rem;
$temp=$temp/10;
}
if($num==$sum)
{
echo "Armstrong number";
}
else
{
echo "not an armstrong number";
}

?>

Results

not an armstrong number

Example 3: armstrongCheck

<?php  
function armstrongCheck($number){ 
    $sum = 0;   
    $x = $number;   
    while($x != 0)   
    {   
        $rem = $x % 10;   
        $sum = $sum + $rem*$rem*$rem;   
        $x = $x / 10;   
    }   
      
    if ($number == $sum) 
        return 1; 
          
    return 0;     
} 
   
$number = 407; 
$flag = armstrongCheck($number); 
if ($flag == 1) 
    echo "Yes it is an Armstrong number"; 
else
    echo "No"
?> 

Results

Yes it is an Armstrong number

I hope you get an idea about Armstrong number in PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.