Armstrong Number in JavaScript


Prev Tutorial Next Tutorial

Armstrong Number Program in JavaScript

Here we use parseInt() function to convert float value into Integer.

Example

<!doctype html>
<html>
<head>
<script>
function armstr()
{
var arm=0,a,b,c,d,num;
num=Number(document.getElementById("no_input").value);

temp=num;
while(temp>0)
{
a=temp%10;
temp=parseInt(temp/10); // convert float into Integer
arm=arm+a*a*a;
}
if(arm==num)
{
alert("Armstrong number");
}
else
{
alert("Not Armstrong number");
}
}
</script>
</head>
<body>
Enter any Number: <input id="no_input">
<button onclick="armstr()">Check</button></br></br>
</body>
</html>

Result

Enter any Number:


Prev Tutorial Next Tutorial

Advertisements




Download Projects