Sha256: 8794373a4a7405d1e10c9ca54d9d18d6272b48bcffc634c8e98da259f8c7303f

Contents?: true

Size: 576 Bytes

Versions: 132

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

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.179 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.178 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.177 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.176 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.175 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.174 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.173 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.172 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.171 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.170 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.169 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.167 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.166 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.165 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.164 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.163 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.162 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.161 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.2.1.160 tracks/c/exercises/perfect-numbers/src/example.c