Check whether a number is an Armstrong number or not with C.
#include <stdio.h>
#include <math.h>
int main()
{
int original, num, lastDigit, digits, sum=0;
printf("Enter any number to check Armstrong number: ");
scanf("%d", &num);
original = num;
digits = (int) log10(num) + 1;// Find total digits in num
while(num > 0)
{
lastDigit = num % 10;
sum = sum + round(pow(lastDigit, digits));
num = num / 10;
}
if(original == sum)
{
printf("%d is ARMSTRONG NUMBER", original);
}
else
{
printf("%d is NOT ARMSTRONG NUMBER", original);
}
return 0;
}
output:-
Enter any number to check Armstrong number : 2552
2552 is NOT ARMSTRONG NUMBER
0 Comments