Start with a bitmask with bits 0 through 9 set, then clear the bits corresponding to values of each variable. If the resultant bitmask is a power of two, all values were distinct+; otherwise, there were duplicates.
int a, b, c, d, e, f, g, h, i;
int mask = 0x3FF; // bits zero through 9 are set
mask &= ~(1<<a);
mask &= ~(1<<b);
...
mask &= ~(1<<i);
if ((mask & -mask) == mask) {
// all bits were distinct
}
See this answer for an explanation of the bit trick used in the last condition.
+ You have ten possible values and nine variables; in order for the nine values to be distinct, they must clear out nine out of ten bits from the bitmask with all ten bits initially set. Removing nine out of ten bits leaves you with only one bit set to
1
, meaning that the result is a power of two.