#include<stdio.h>
#include<math.h>
int armstrong(int n) ///receive the number
{
double k,fact=1;
double array[100];
double pow_sum=0;
int i=-1,j;
double number=n;
///saving the number by 1 digit
while(n!=0)
{
i++;
array[i]=n%10;
n=n/10;
}
///calculate per digit power and add them
for(j=0;j<=i;j++)
{
pow_sum = pow_sum + pow(array[j],i+1);
}
/// Compare total factorial value with the main number
if(pow_sum==number)
{
printf("
This is an Armstrong Number
");
}
else
{
printf("
This is not an Armstrong Number
");
}
}
int main()
{
int n;
printf("Please Enter A Number: ");
scanf("%d",&n);
armstrong(n); ///function call
return 0;
}
What is Armstrong Number?- https://codetohaven.blogspot.com/2018/01/what-is-armstrong-number.html
Output
Please Enter A Number: 135
This is not an Armstrong Number
Add your comment