Check whether a number is Armstrong number or not using C beginner level
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to check whether a number is Armstrong number or not using C.
Now what is an Armstrong number,
It is basically a number which can be defined as the sum of the cube of the digits of the number is known as the Armstrong number.
#include<stdio.h>
#include<math.h>
int main()
{
int cpy,num,sum=0;
printf("Enter a number");
scanf("%d",&num);
cpy = num;
while(cpy>0)
{
int i=cpy%10;
sum += pow(i,3);
cpy=cpy/10;
}
if(sum==num)
{
printf("The number is an Armstrong number");
}
else
printf("The number is not an armstrong number");
return(0);
}
Comments
Post a Comment