JavaScript program to check given 3-digit number is Armstrong or not? (12)
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
let n =parseInt(prompt("Enter a 3 digit number"));
let m=n;
document.write("Given number is :"+n);
let p = 0;
while(n>0)
{
r = n%10;
p = p + r*r*r;
n = Math.floor(n/10);
}
if(p==m)
{
document.write("<br> Armstrong Number");
}
else
{
document.write("<br> Not Armstrong Number");
}
</script>
</body>
</html>
Comments
Post a Comment