Tuesday, 11 August 2015

How To Find Armstrong Number In Php

Php program for Armstrong number
Definition: -  Armstrong number is a number which is equal to a Sum of digits raise to the power total number of digits in the number.Here Is PHP program for Armstrong Number In this post we will help you to learn how to find Armstrong number in PHP. To run this program copy paste this code and save it as any name but with ".php" extension.  

<body bgcolor="#C5FF13">
<title>Php program for armstrong number</title>

 <!-- to test this script type 371 or 407, these are Armstrong numbers -->

 <h2 align="center">Php Program For Armstrong Number</h2>
<h3> Program Bye Helps2code.com</h3>
 <form action="" method="post">
<table border="1" align="center"> <tr> <td>  <input type="text" name="number" placeholder="Enter A Number" /></td></tr>
<tr><td>  <input type="submit"/></td></tr></table>



 if( $_POST )
  //get the enter number
  $number = $_POST[ 'number' ];

  //store it in a temp variable
  $temp = $number;
  $sum  = 0;

  //loop till the quotient is 0
  while( $temp != 0 )
   $rem   = $temp % 10; //find reminder
   $sum   = $sum + ( $rem * $rem * $rem ); //cube the reminder and add it to the sum variable till the loop ends
   $temp   = $temp / 10; //find quotient. if 0 then loop again

  //if the entered number and the $sum value matches then it is an ARMSTRONG NUMBER
  if( $number == $sum )
   echo "Armstrong Number";
   echo "Not an Armstrong Number";


After saving this program open your WAMP Or XAMP Server and run it.
If You find This Program Helpful Leave A Comment And Do Share With Your Friends.
Php Program of Armstrong Number
Php Program of Armstrong Number
Other Php Program For helping You: :)


Post a Comment