program to generate and print armstrong numbers
armstrong number in c: This program prints armstrong number. In our program we ask the user to enter a number and then we use a loop from one to the entered number and check if it is an armstrong number and if it is then the number is printed on the screen. Remember a number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are 0, 1, 153, 370, 407.
armstrong number in c: This program prints armstrong number. In our program we ask the user to enter a number and then we use a loop from one to the entered number and check if it is an armstrong number and if it is then the number is printed on the screen. Remember a number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are 0, 1, 153, 370, 407.
C code
#include
#include
#include
main()
{
int r;
long number = 0, c, sum = 0, temp;
printf("Enter the maximum range upto which you want to find armstrong numbers ");
scanf("%ld",&number);
printf("Following armstrong numbers are found from 1 to %ld\n",number);
for( c = 1 ; c <= number ; c++ )
{
temp = c;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( c == sum )
printf("%ld\n", c);
sum = 0;
}
getch();
return 0;
}
Output of program
![](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uhug92l8akUVQh5ie_6tRBUt8wrPppqwHkkJ9kTEvy8nZGra1GQkHljhRYHDFLCdQMmHGkoWx2IG_YsUOg-1b6HrQTT9GzBpw9gbl5JC54GcAwma7gojflhhqF86HE9KmUVF291IooaG9vl6rlfcDp7HIYfSswT9_PXQ=s0-d)