write a JavaScript program to find armstrong numbers
Answers
<!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>
An Armstrong number is a number whose sum of cubes of digits is equal to the number itself.
For example:
153 = 1³+5³+3³
1+125+27
=153
Program:
import java. util.*;
class Armstrong
{
public static void main (string args [])
{
Scanner sc = new Scanner
int n, r, p, s=0, m;
System.out.println ("Enter a number");
n=sc.nextInt();
while
{
r=n%10
p=r*r*r;
s=s+p;
n=n/10;
}
if (m==s)
System.out.println (m+"is Armstrong");
else
System.out.println (m+"is not Armstrong");
}
}