User Tools

Site Tools


haas:spring2014:cprog:projects:vertcross

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:vertcross [2014/03/13 09:23] – [Multiplying two three-digit numbers together] wedgehaas:spring2014:cprog:projects:vertcross [2014/03/13 09:42] (current) – [Multiplying two double digit numbers together] wedge
Line 77: Line 77:
       4        1         1       4        1         1
               2         0               2         0
 +              
 +      4+2      1         1
 +      
 +      6        1         1
                              
               = 611               = 611
Line 87: Line 91:
 In this case we merely extend the pattern of vertically and crosswise, namely: In this case we merely extend the pattern of vertically and crosswise, namely:
  
-  * there are 3 columns to multiply vertically +  * multiply right-most column vertically (ones place) 
-  * there are 2 crosswise operations to perform+  * multiply crosswise the two right-most columns (tens place) 
 +  * multiply crosswise the left- and right-most columns, vertically multiply the middle (hundreds) 
 +  * multiply crosswise the two left-most columns (thousands) 
 +  * multiply vertically the left-most column (ten thousands) 
 + 
 +Note the stretching/expanding approach that is taken here-- with each successive place, the range of columns involved in that position's calculation grows (including an additional column to the left with each position), until all columns are involved, then we shrink it progressively one column at a time (removing columns from the right) as we wane down to a single column on the left.
  
 Let's look at 123 x 234: Let's look at 123 x 234:
Line 95: Line 104:
    123    123
  x 234  x 234
- ------- + -------        carry_in 
-  (1x2)         (2x3)         (3x4   the vertical multiplications +     3x4          [+ 0] ones place    (sum of 2 carry out of 1) 
-      (1x3)+(2x2)   (2x4)+(3x3       the crosswise operations +    2x4 3x3      + 1  tens place    (sum of 8 carry out of 1) 
-             (1x4)+(2x3)               an outer-most crosswise operation +   4x1 + 2x3 2x3 + 1  hundreds      (sum of 7 carry out of 1
-  --------------------------------- +  1x3 2x2        + 1  thousands     (sum of 8 carry out of 0) 
-    02   06    12                      as this is a 3 digit problem, we need places + 2x1               + 0  ten thousands (sum of carry out of 0) 
-      3+4   8+9 + 
-         4+6 +  We then take the sums from each operation and place them as appropriate 
-  ------------------ + in their position in the final number (ones place is furthest on the right). 
-    020612 + 
-     0717 + 123 x 234 = 28782
-      10 +
-    ------ +
-    028782 = 28782 (as a leading zero does not impact the value at all)+
 </code> </code>
  
 A dual benefit of this project is that in addition to extending your programming experience / understanding of C, you could develop this as a mental ability (that is where it originated), and you could then use it as a means of checking your work. A dual benefit of this project is that in addition to extending your programming experience / understanding of C, you could develop this as a mental ability (that is where it originated), and you could then use it as a means of checking your work.
- 
 ====Another depiction==== ====Another depiction====
 Here is another, more illustrative, method of solving a problem using the vertical and crosswise method: Here is another, more illustrative, method of solving a problem using the vertical and crosswise method:
Line 136: Line 141:
     * if there is only 1 argument, ask the user for the second number     * if there is only 1 argument, ask the user for the second number
     * if there are no arguments, ask the user for both numbers     * if there are no arguments, ask the user for both numbers
-  * determine from the input if it is a one-, two-, or three-digit number+  * determine from the input the quantity of digits in each number 
     * add any leading zeros in order to match the length of both numbers     * add any leading zeros in order to match the length of both numbers
-  * perform the correct algorithm against the input+  * perform the correct algorithm (vertical and crosswise) against the input
   * implement said algorithm in a function that is called   * implement said algorithm in a function that is called
   * propagate any carries   * propagate any carries
Line 144: Line 149:
  
 =====Execution===== =====Execution=====
-Several operating behaviors are shown, namely, with and without command-line arguments and 1-, 2-, and 3-digit values.+Several operating behaviors are shown, namely, with and without command-line arguments and 2-, and 3-digit values.
  
 First up, two-digit values without argument: First up, two-digit values without argument:
Line 165: Line 170:
 </cli> </cli>
  
-=====Reflection===== 
-Be sure to provide any commentary on your opus regarding realizations had and discoveries made during your pursuit of this project. 
- 
-  * Can this process be extended for four digit numbers? 
-  * How about five digit numbers? 
  
 =====Submission===== =====Submission=====
haas/spring2014/cprog/projects/vertcross.1394702599.txt.gz · Last modified: 2014/03/13 09:23 by wedge