- C Programming Code To Check Whether A Number Is An Armstrong Number Or Not An Armstrong Number Is A Number Which Is Equ 1 (38.05 KiB) Viewed 37 times
C programming code to check whether a number is an Armstrong number or not. An Armstrong number is a number which is equ
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
C programming code to check whether a number is an Armstrong number or not. An Armstrong number is a number which is equ
C programming code to check whether a number is an Armstrong number or not. An Armstrong number is a number which is equal to the sum of digits raise to the power of the total number of digits in the number. Some Armstrong numbers are: 0, 1, 2, 3, 153, 370, 407, 1634, 8208, etc. The algorithm to do this is: First we calculate the number of digits in our program and then compute the sum of individual digits raise to the power number of digits. If this sum equals the input number, then the number is an Armstrong number otherwise not. Examples: 7=7^1 371 = 3^3 +7^3 + 1^3 (27+ 343 +1) 8208 = 8^4 + 2^4 +0^4 + 8^4 (4096 + 16 +0+4096). Sample Input: 371 Sample Output: Total number of digits- 3 3^3=27 7^3= 343 1^3= 1 Sum= 371 ARMSTRONG NUMBER!