Sha256: 4b78cb5bdcea99d78db80b446c6ad84dbd1f135dc14b6e3108648609055a33d9

Contents?: true

Size: 576 Bytes

Versions: 108

Compression:

Stored size: 576 Bytes

Contents

#include "perfect_numbers.h"

static int aliquot_sum(int n)
{
   if (n == 1) {
      return 0;
   }
   int result = 1;
   int i;
   for (i = 2; i * i < n; ++i) {
      if ((n % i) == 0) {
         result += i + (n / i);
      }
   }
   return result + (i * i == n ? i : 0);
}

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

108 entries across 108 versions & 1 rubygems

Version Path
trackler-2.2.1.26 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.25 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.24 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.23 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.22 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.21 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.20 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.19 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.18 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.17 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.16 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.15 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.14 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.13 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.12 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.11 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.10 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.9 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.8 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.7 tracks/c/exercises/perfect-numbers/src/example.c