Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!cs.umn.edu!talon.UCS.ORST.EDU!usenet!ogicse!intelhf!ichips!iwarp.intel.com!inews!hopi!bhoughto From: bhoughto@hopi.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Divide and C Message-ID: <3508@inews.intel.com> Date: 28 Mar 91 02:37:50 GMT Article-I.D.: inews.3508 References: <1991Mar27.185804.7221@uunet.uu.net> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 24 In article <1991Mar27.185804.7221@uunet.uu.net> karln!karln@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..."