User Tools

Site Tools


haas:spring2014:cprog:projects:nikhilam

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:spring2014:cprog:projects:nikhilam [2014/02/24 13:58] – [Program] wedgehaas:spring2014:cprog:projects:nikhilam [2014/02/24 14:15] (current) – [Nikhilam Multiplication] wedge
Line 90: Line 90:
   - Pick a number (top or bottom, doesn't matter) and add it to the other number's short value (97 + -6, or 94 + -3)   - Pick a number (top or bottom, doesn't matter) and add it to the other number's short value (97 + -6, or 94 + -3)
   - That result goes down as the left hand side of our answer, and barring any carries or deficiencies in the right hand side, may well be set   - That result goes down as the left hand side of our answer, and barring any carries or deficiencies in the right hand side, may well be set
-  - For the right hand side, multiply those two short values together (-6 * -3 = +18). THAT is the right hand side+  - For the right hand side, multiply those two short values together (-6 * -3 = +18). THAT is the right hand side (a point to consider: because the common power is 100 in this case, the right hand side needs to be 2 digits)
   - Concatenate the two together, and you get: **9118**   - Concatenate the two together, and you get: **9118**
 +
 +===Excess===
 +And what about cases where the numbers are in excess of their common base? **Same thing**:
 +
 +<code>
 +
 +    103  +3     103 is 3 above 100
 +  x 107  +7     107 is 7 above 100
 +    === ===
 +  103+7 3*7     half cross add on the left, multiply excess numbers on right
 +    110  21     make sure right hand value is 2 digits (100 = 10 to the 2nd power)
 +    
 +    11021
 +</code>
 +
 +===Mixed===
 +And how about mixed? One in excess, one short?
 +
 +<code>
 +
 +    106  +6      6 in excess of 100
 +  x  97  -3      3 short of 100
 + ======  ===== 
 + 106+-3  +6*-3   same deal as always- half cross add, multiply differences
 +    103  -18
 +    
 +</code>
 +
 +Now, because the right hand value is negative, we have a "borrow" operation that needs to happen... we essentially have the following problem to consider:
 +
 +<code>
 +
 +    103    100
 +    1   - 18
 +   ====   ====
 +    102     82 <-- all by nine, last by 10
 +    
 +    10282          and voila! Our answer.
 +</code>
 =====Program===== =====Program=====
 It is your task to write the program that will use the above method to multiply two numbers together (you can make the assumption that the user will only ever be putting in values close to a common base). It is your task to write the program that will use the above method to multiply two numbers together (you can make the assumption that the user will only ever be putting in values close to a common base).
Line 105: Line 144:
 <cli> <cli>
 lab46:~/src/cprog/nikhilam$ ./nikhilam lab46:~/src/cprog/nikhilam$ ./nikhilam
-Enter value34 +Enter first number91 
-34 34 5625+Enter second number: 99 
 +91 99 9009
 lab46:~/src/cprog/nikhilam$  lab46:~/src/cprog/nikhilam$ 
 </cli> </cli>
haas/spring2014/cprog/projects/nikhilam.1393250312.txt.gz · Last modified: 2014/02/24 13:58 by wedge