Sha256: df98261769704b87e6c3e39f45143680248064d2a42efb4a3714cadda1f83eb5

Contents?: true

Size: 801 Bytes

Versions: 60

Compression:

Stored size: 801 Bytes

Contents

#include "palindrome_products.h"
#include <stdbool.h>

/* Return true if the product of a and b is a palindrome, false otherwise */
bool is_palindrome_product(int a, int b)
{
   int ret = 0, prod = a * b;
   while (prod) {
      ret *= 10;
      ret += prod % 10;
      prod /= 10;
   }
   return (a * b) == ret;
}

product_t get_palindrome_product(int min, int max)
{
   product_t ret;
   ret.smallest = 0;
   ret.largest = 0;
   bool largest = false;

   for (int i = min; i <= max; i++) {
      for (int j = min; j <= max; j++) {
         if (is_palindrome_product(i, j) == true) {
            if (largest == false) {
               ret.smallest = i * j;
               largest = true;
            } else {
               ret.largest = i * j;
            }
         }
      }
   }
   return ret;
}

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.104 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.103 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.102 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.101 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.100 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.99 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.98 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.97 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.96 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.95 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.94 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.93 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.92 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.91 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.90 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.89 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.88 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.87 tracks/c/exercises/palindrome-products/src/example.c
trackler-2.2.1.86 tracks/c/exercises/palindrome-products/src/example.c