C program armstrong numberWhat is an Armstrong number?

An ‘n’ digit number is equal to the sum of n-th power of its digits.

Ex: 371 is an Armstrong number.

3*3*3+7*7*7+1*1*1 = 371

About this program

This program takes a three digit number from the user and checks whether the number is Armstrong or not.

LOGIC

(i) Take a three digit number from user.

Ex: 561

(ii) Separate the digits of it. To separate the individual digits of a three digit number see the logic of the program: Sum of digits of a three digit number.

(iii) Now only one thing is left is to get the sum of cubes of its digits and compare it with the actual number. To do this multiply each digit three times and add the three results.

Ex: ((5*5*5)+(6*6*6)+(1*1*1)) = 342

(iv) Compare the final result with the actual number. If both are equal then display “Armstrong”.

Ex: Is 561 = 342? No. So 561 is not Armstrong.

CODE

OUTPUT

Check whether a three digit number is Armstrong or not – C Program
Tagged on:

Leave a Reply

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