Which are armstrong numbers?
Numbers whose sum of cube of digits is equal to the number itself.
e.g. if we take 153 than
13 =1
53=125
33=27 and sum of all of them is 1+125+27=153
so 153 is a armstrong number.
Code in c :
#include < stdio.h >
#include < conio.h >
void main() {
int number, f_num, s_num, t_num;
clrscr();
for (number = 1; number <= 500; number++) { // loop to check upto 500
f_num = number / 100;
s_num = (number % 100) / 10;
t_num = (number % 100) % 10;
if (((f_num * f_num * f_num) + (s_num * s_num * s_num) + (t_num * t_num * t_num)) == number) // condition to check if armstrong number
printf("%d\n", number);
}
getch();
}