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.46 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.45 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.44 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.43 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.42 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.41 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.40 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.39 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.38 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.37 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.36 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.35 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.34 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.33 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.32 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.31 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.30 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.29 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.28 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.27 tracks/c/exercises/perfect-numbers/src/example.c