/ Published in: C

Check that a given integer consists only of elements of a given set. It does a linear search through the set, so the assumption is that the set to search is relatively small. If you're chewing through a particularly large set of digits, you may want to sort your set and implement a binary search.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
bool testProduct(int number, int numDigits, int[] digits) { int x = 0; int i = 0; bool found = false; while (number > 0) { i = number % 10; number /= 10; for (x = 0; x < numDigits; x++) { if (digits[x] == i) { found = true; break; } } if (!found) return false; found = false; } return true; }
Comments
