C program to check Armstrong number
#include<stdio.h>
#include<math.h>
int isarmstrong(int d ,int num)
{
int r,n=num,sum=0;
while(n>0)
{
r=n%10;
sum=sum+pow(r,d);
n=n/10;
}
if(sum==num)
return 1;
else
return 0;
}
int main ()
{
int n,num,c=0;
printf("enter the number = ");
scanf("%d",&n);
num=n;
while(n>0)
{
c=c+1;
n=n/10;
}
if(isarmstrong(c,num))
printf(" this is a armstrong number ");
else
printf("this is not a armstrong number");
return 0;
}
Post a Comment
0 Comments