C program to print Armstrong numbers from 1 to 1000

#include<stdio.h>
#include<conio.h>
int main()
{

int num, n, cube, d, sum;

printf("Armstrong numbers are : \n");
for (num = 100; num <= 999; num++)
{

n = num;
sum = 0;
while(n > 0)

{

d = n % 10;
n /= 10;
cube = d*d*d;
sum = sum + cube;
}

if (num == sum)
printf("%d\n", num);

}
return 0;
}

Output:-


 

Leave a Reply

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