Skip to content

Instantly share code, notes, and snippets.

@kYroL01
Last active July 12, 2021 16:39
Show Gist options
  • Save kYroL01/7ba05f8197d5a06d1a18f8e77fcc2ec2 to your computer and use it in GitHub Desktop.
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.
#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