[OCLUG-devel] calculations one digit at a time

James Colannino james at colannino.org
Sun Jul 11 09:27:44 PDT 2004


Hey everyone.  I'm trying to figure out how I'm going to do calculations 
working with one digit at a time (this is so that I can work with fixed 
digit numbers.)  For example:

110 + 100

First, the two 0's in the one's place would be added, then the 0 and the 
1 in the tens place, and finally the two 1's in the hundreds place.  At 
first glance, it doesn't seem like it would be too difficult.  I would 
assign each individual digit to its own variable and go from there.  The 
problem is, if I add two numbers and I get a number that's equal to 10 
or greater, I'll have to figure out how to borrow, and I'm not quite 
sure how to do that in C.

For example:

732 + 298

8 + 2 is 10, so I would have to move the 1 digit in the tens place over 
one.  Would I maybe convert 10 into a string, split it into the 1 and 0, 
and then convert both back into integers and add them to their 
appropriate places?

I hope I'm not too out there with my solution :-P  I'm just not quite 
sure what I should do.

James
-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"There are no uninteresting things; only uninterested people." --G.K. 
Chesterton



More information about the OCLUG-devel mailing list