24. JavaScript 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 JavaScript.
- 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>JavaScript program to Check a given number is Automorphic or Not</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter a number"> </td>
</tr>
<tr>
<td> <button onclick="automorphic ()" >Submit</button></td>
</tr>
</table>
<div id="num"></div>
<div id="num1"></div>
</body>
<script type="text/javascript">
function automorphic()
{
var n,m;
n = parseInt(document.getElementById ("first").value);
m = n*n;
document.getElementById ('num').innerHTML ="Square of a number is: "+m;
if(n%10 != m%10)
{
document.getElementById('num1').innerHTML = n +" is not an atomorphic number";
n = n/10;
m = m/10;
}
else
{
document.getElementById('num1').innerHTML = n +" is an automorphic number";
}
}
</script>
</html>