<html><head><title>Armstrong number or not</title>
<script>
function Armstrong()
{
var flag,number,remainder,addition = 0;
number = Number(document.getElementById("num").value);
flag = number;
while(number > 0)
{
remainder = number%10;
addition = addition + remainder*remainder*remainder;
number = parseInt(number/10);
}
if(addition == flag)
{
window.alert("The input number is Armstrong");
}
else
{
window.alert("The input number is not Armstrong");
}
}
</script></head>
<body>
<h1>Whether a number is Armstrong or not</h1>
Enter the number :<input type="text" name="n" id = "num"/><br/>
<input type="submit" value="CHECK" onClick="Armstrong()" />
</body>
</html>
For example Armstrong numbers are : 153 370 371 407
Output:
No comments:
Post a Comment