Friday, 26 September 2014

A program to check the number is Armstrong or Not

public class armstrong
{
public static void main(String args[])
{
int n,r,sum,p,x,count;
n=370;
count=0;
sum=0;
p=n;
x=n;

while(n!=0)
{
count++;
n/=10;
}

while(p!=0)
{
r=p%10;
sum+=Math.pow(r,count);
p=p/10;
}

if(sum==x)
System.out.print("Armstrong");
else
System.out.print("Not");

}

}

No comments:

Post a Comment