Pages

Saturday, 20 June 2015

Armstrong number

Check a given number is an Armstrong number or not

Coding:
#include<stdio.h>
int main()
{
int n,x,i,no,d=0,sum=0,p,r;
printf("PLease enter the number:");
scanf("%d",&n);
no=n;
while(n>0)
{
n=n/10;
d++;
}
n=no;
while(n>0)
{
r=n%10;
n=n/10;
p=1;
for(i=1;i<=d;i++)
{
p=p*r;
}
sum=sum+p;
}
if(sum==no)
{
printf("%d is an Armstrong no",no);
}
else
{
printf("%d not an Armstrong no",no);
}
return 0;
}

Output:
PLease enter the number:153
153 is an Armstrong no