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