Last active
July 12, 2021 16:39
-
-
Save kYroL01/7ba05f8197d5a06d1a18f8e77fcc2ec2 to your computer and use it in GitHub Desktop.
Armstrong number: An n-digit number equal to the sum of the n-th powers of its digits.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
int is_armstrong_number(int x) | |
{ | |
int i = 0, c_pow = 0, sum = 0; | |
int digit = x; | |
int module = x; | |
while(digit != 0) { | |
digit /= 10; | |
c_pow++; | |
} | |
digit = x; | |
while(i++ < c_pow) { | |
digit %= 10; | |
sum += pow((double)digit, c_pow); | |
module /= 10; | |
digit = module; | |
} | |
return (x == sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment