You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
340 B
17 lines
340 B
3 years ago
|
#include "armstrong_numbers.h"
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
bool is_armstrong_number(int candidate) {
|
||
|
char buffer[15];
|
||
|
sprintf(buffer, "%d", candidate);
|
||
|
int exponent = strlen(buffer);
|
||
|
int sum = 0;
|
||
|
for (int i = 0; i < exponent; i++) {
|
||
|
sum += pow(buffer[i] - 48, exponent);
|
||
|
}
|
||
|
|
||
|
return candidate == sum;
|
||
|
}
|