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

Version Path
trackler-2.1.0.0 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.55 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.54 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.53 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.52 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.51 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.50 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.49 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.48 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.47 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.46 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.45 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.44 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.43 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.42 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.41 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.40 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.39 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.38 tracks/c/exercises/perfect-numbers/src/example.c
trackler-2.0.8.37 tracks/c/exercises/perfect-numbers/src/example.c