Untitled
unknown
plain_text
4 years ago
433 B
8
Indexable
// Checks if a number is divisible by sum of its digits
bool is_divisible(long x) {
// Save initial input
long temporary = x;
// Sum all digits of the number
int sum_digits = 0;
while (x != 0) {
int y = (int) x % 10;
sum_digits = (sum_digits + y);
x /= 10; // To next digit
}
// Control statement
if (temporary % sum_digits == 0) {
return true;
} else {
return false;
}
}Editor is loading...