Divide and C
Blair P. Houghton
bhoughto at hopi.intel.com
Thu Mar 28 12:37:50 AEST 1991
In article <1991Mar27.185804.7221 at uunet.uu.net> karln!karln at uunet.uu.net (Karl Nicholas) writes:
> EX: int array[10][10];
> val = 24;
> ++array[val/10][val%10];
ANS: int array[10][10]; /* for example */
int dividend, remainder; /* to use as array indices */
val = 24; /* for example */
dividend = val/10;
remainder = val - val*dividend; /* the definition of `%' */
++array[dividend][remainder]; /* dividend more significant */
This depends on the fact that an integer division
takes even longer than two assignments, a multiplication,
a subtraction, and whatever hocus-pocus the compiler
uses when it sees variables in the array indices...
--Blair
"Lawyer: never ask a question to which
you don't already know the answer.
Programmer: never ask a question to
which you do already know the answer..."
More information about the Comp.lang.c
mailing list