An Armstrong number or Narcissistic number is an n-digit base b number such that the sum of its (base b) digits raised to the power n is the number itself.
Example 1:
If number = 153
It has 3 digits: 1, 5 and 3. So n = 3.
result = 13 + 53 + 33 = 1 + 125 + 27 = 153.
So the original number 153 is equal to the result. So it’s an Armstrong Number.
Example 2:
If number = 1634
It has 4 digits: 1, 6, 3 and 4. So n = 4.
result = 14 + 64 + 34 + 44 = 1 + 1296 + 81 + 256 = 1634.
So the original number 1634 is equal to the result. So it’s an Armstrong Number.
Related Read:
C Program To Reverse a Number
Basic Arithmetic Operations In C
while loop in C programming
if else statement in C
Calculate Sum of Digits: C Program
C Program to Check Armstrong Number
C Program to print Armstrong Numbers between 1 and 500
C Program to print Armstrong Numbers Between Two User Entered Integers
Page Contents
num = temp = count; n = sum = 0; while(temp) { temp = temp / 10; n++; }
while(num) { rem = num % 10; sum = sum + pow(rem, n); num = num / 10; }
To know above code logic, please visit and watch the video tutorial present at C Program to Check Armstrong Number.
#include < stdio.h > #include < math.h > int main() { int count, limit, rem, temp, num, n; float sum; printf("Enter 2 integer numbers\n"); scanf("%d%d", &count, &limit); printf("\nArmstrong numbers between %d and %d\n", count, limit); while(count <= limit) { num = temp = count; n = sum = 0; while(temp) { temp = temp / 10; n++; } while(num) { rem = num % 10; sum = sum + pow(rem, n); num = num / 10; } if(count == sum) { printf("%d is Armstrong number\n", count); } count++; } return 0; }
Output:
Enter 2 integer numbers
1
99999
Armstrong numbers between 1 and 99999
1 is Armstrong number
2 is Armstrong number
3 is Armstrong number
4 is Armstrong number
5 is Armstrong number
6 is Armstrong number
7 is Armstrong number
8 is Armstrong number
9 is Armstrong number
153 is Armstrong number
370 is Armstrong number
371 is Armstrong number
407 is Armstrong number
1634 is Armstrong number
8208 is Armstrong number
9474 is Armstrong number
54748 is Armstrong number
92727 is Armstrong number
93084 is Armstrong number
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert