• iconJava Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

Armstrong Number

Armstrong Armstrong Number: A positive number is called armstrong number if it is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.
Let's try to understand why 153 is an Armstrong number.
153 = (1*1*1)+(5*5*5)+(3*3*3)
where:
(1*1*1)=1
(5*5*5)=125
(3*3*3)=27
So:
1+125+27=153



Java Training in Andhra Pradesh and Telangna

Java Training in Andhra Pradesh and Telangna

public class Main 
{

    public static void main(String[] args)
    {
     int c=0,a,temp;  
        int n=153;//It is the number to check armstrong  
        temp=n;  
        while(n>0)  
        {  
        a=n%10;  
        n=n/10;  
        c=c+(a*a*a);  
        }  
        if(temp==c)  
        {
        System.out.println("armstrong number");
        }
        else  
        {
            System.out.println("Not armstrong number");  
        }
    }  
}

                                

Output:
armstrong number

c=0;a=0;temp=0
n=153; #It is the number to check armstrong  
temp=n;  
while(n>0):
    a=n%10;  
    n=n//10;  
    c=c+(a*a*a);  
  
if(temp==c):
    print("armstrong number");
	    
else:
    print("Not armstrong number");  
	   


                                

Output:
armstrong number



Improve Your Knowledge

Daily 10 Minite Reading