Program to find Armstrong number
What is Armstrong number
If sum of cube of each digit in number is equal to that number then its called as armstrong number
Ex.1
Conceder number 153
Calculate sum of cube of 1,5 and 3
1^3+5^3+3^3=153
Hence 153=153
Then 153 is Armstrong number
Ex.2
Conceder number 122
1^3+2^3+2^3=17
Then 122 is not Armstrong
number
class armstrong
{
public static void
main(String args[])
{
int
i,p,rem,sum,n=999;
for(i=0;i<n;i++)
{
p=i;
sum=0;
while(p!=0)
{
rem=p%10;
p=p/10;
sum=sum+(rem*rem*rem);
}
if(sum==i)
System.out.println(
"amstrong="+i);
}
}
}
No comments:
Post a Comment