Sha256: 9a1cd66a8f35625311f107d3e61dd8de05e266ad6109de11dcb9b6d2bffb7826
Contents?: true
Size: 503 Bytes
Versions: 20
Compression:
Stored size: 503 Bytes
Contents
#include "perfect_numbers.h" static int aliquot_sum(int n) { int result = 0; for (int i = 1; i < n; ++i) { if ((n % i) == 0) { result = result + i; } } return result; } kind classify_number(int n) { kind class = error; if (n > 0) { int sum = aliquot_sum(n); if (sum > n) { class = abundant_number; } else if (sum < n) { class = deficient_number; } else { class = perfect_number; } } return class; }
Version data entries
20 entries across 20 versions & 1 rubygems