28. Armstrong number checking :—
#include<stdio.h>
int main()
{
int i,n,m,k,r,sum;
printf("enter value of n ");
scanf("%d",&n);
m=n;
k=0;
while(n>0)
{
n=n/10;
k++;
}
n=m;
sum=0;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+pow(r,k);
}
if(sum==m)
{
printf("It is an Armstrong number");
}
else
{
printf("It is not an Armstrong number");
}
return 0;
}
No comments:
Post a Comment