59. PHP Program to find the given number is Automorphic or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Automorphic number or not using PHP.
- An Automorphic number is a number whose square ends with the number itself.
- First find the square of a number itself, After that check the condition followed by given logic then we get the Output.
Here is the code
<html>
<head>
<title>PHP Program To Check a given number is Automorphic or Not</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num'];
$sq = $n * $n; // First find square number itself
// Condition for checking Automorphic
if ($sq%10 == $n || $sq%100 == $n || $sq%1000 == $n)
echo "$n is an Automorphic number"." ";
else
echo "$n is not an Automorphic number";
return 0;
}
?>
</body>
</html>