Armstrong number between 1 to 100 by R4R Team

Armstrong number:
-A number which is equal to the sum of the power of digit by its length is called as Armstrong number.

Example-
1,2,3,4,5,6,7,8,9
these all are Armstrong number
370,371 are Armstrong number.
How ?
370=3^3+7^3+0^3
-Here '^' shows the power function.
-Here we print the all possible Armstrong number betweeen the 0 and 1000

program-

#include < stdio.h>
#include
int armstrong(int n,int length)
{
int sum=0,n1;
n1=n;
while(n1)
{
sum=sum+pow(n1%10,length);
n1=n1/10;
}
if(sum==n)
return 1;
else
return 0;
}
int length(int n)
{
int length=0;
while(n)
{
length++;
n=n/10;
}
return length;
}
int main()
{
int i=0;
printf("Armstrong number between 0 to 1000\n");
for(i=0;i<1000;i++)
{
if(armstrong(i,length(i)))
printf("%d,",i);
}
}


output-

Armstrong number between 0 to 1000
0,1,2,3,4,5,6,7,8,9,153,370,371,407,




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!