Armstrong Number in C 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.

program-

#include < stdio.h>
#include < math.h>
int main()
{
int n,length=0,sum=0,n1;
printf("Enter Number\n");
scanf("%d",&n);
n1=n;
while(n)
{
length++;
n=n/10;
}
n=n1;
while(n)
{
sum=sum+pow(n%10,length);
n=n/10;
}
if(sum==n1)
printf("Number is Armstrong numbern");
else
printf("Number is not armstrong");
}


output-

Enter Number
371
Number is Armstrong number

Enter Number
5
Number is Armstrong number

Enter Number
67
Number is not armstrong

-In this program, we take a input of the integer number and try to check that number is armstrong or not.




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!