Algorithm to check wheather the given number
is armstrong number or
not
Answers
Answered by
3
Answer is in the attachment, check it out!
Attachments:
Answered by
3
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");
}
}
Similar questions
Social Sciences,
1 month ago
English,
1 month ago
Math,
2 months ago
Math,
9 months ago
English,
9 months ago