Check Armstrong Number or not !

Program to check Armstrong number :

Armstrong number of n digit is the one in which the sum of the nth power of the individual digits of the number is equal to that number. Example :



Following is the algorithm and java program to check  armstrong number input by user :

Algorithm :

  1. Input a number, n
  2. Set num=n, length=0,i=0,sum=0
  3. [ Find the number of digits ]
    while num>0, Repeat 4-5
  4. Set length=length+1
  5. Set num=num/2
  6. Set num=n
  7. while i<length, Repeat 8-10
  8. ct=n%10
  9. n=n/10
  10. sum=sum+ctlength
  11. Check if sum=num
    print “Armstrong Number”/
  12. Otherwise
    print “Not an Armstrong Number”

Source Code :

Output :

Enter the Number : 24
Not an Armstrong number.

Leave a Reply

Your email address will not be published. Required fields are marked *