Before writing the the C program to check Armstrong Number, lets see what is Armstrong number.
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
For Example, 153, 371 are Armstrong number. Lets see why
153 = (1)3 + (5)3 + (3)3 153 = 1 + 125 + 27 153 = 153
371 = (3*3*3)+(7*7*7)+(1*1*1) (3*3*3)=27 (7*7*7)=343 (1*1*1)=1 So: 27+343+1=371
Now let see the C Program to Check Armstrong Number
#include <stdio.h> int main() { int arms = 153; int check, rem, sum = 0; check = arms; while(check != 0) { rem = check % 10; sum = sum + (rem * rem * rem); check = check / 10; } if(sum == arms) printf("%d is an armstrong number.", arms); else printf("%d is not an armstrong number.", arms); return 0; }
Output of the program should be
153 is an armstrong number.
Also check the Factorial Program in C
[…] Also see the C Program to Check Armstrong Number […]