Corning Community College
CSCS1320 C/C++ Programming
~~TOC~~
To implement a programmatic solution (ie simulation) of a real life process- the mental math trick of multiplying any one-, two-, or three-digit number by eleven.
In addition to the new skills required on previous projects, to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:
The allure of using (and learning) a programming language is to be able to effectively use it to solve problems, which in and of themselves are simulations of some process we can do in “the real world”.
In this case, we will be writing a program which will implement the mental math techniques for multiplying any one-, two-, or three-digit number by eleven.
Mental Math constitutes an intersection of mental tricks and math- instead of utilizing a purely math-only solution, manipulations or simplifications in the computational process may take place enabling an individual to, once having learned the process, solve such problems in their head, and typically without the use of a calculating device.
The process in this case is one of pattern matching, number manipulation, and simple arithmetic. To wit:
This may be a pattern of which you are already aware- to multiply any single-digit number (base 10) by eleven, you simply duplicate the digit twice.
In the case of 1 x 11, we get: 11
For 2 x 11, we see: 22
For 3 x 11, we have: 33
and this trick works all the way through 9 x 11, yielding: 99
Here we do a pivot and then perform simple arithmetic to obtain the middle value.
In the case of 10 x 11, we take 10 and pivot it, getting 1 and 0, respectively our first and last digit of our soon-to-be solution.
To get the middle value, we add these two values together: 1+0=1
So, the result of 10 x 11 is: 1 (1+0) 0 or: 110
Let's try it with 32 x 11:
32 x 11 = 3 (3+2) 2 = 3 5 2 = 352
This is almost the entire process, but there's one other factor we need to be aware- if the summing of the first and last values yields a value greater than 10, we must propagate the carry to the next digit to the left (i.e. the first digit).
For example, let us take the maximum two digit value (99):
Using this process as it has been described thus far, we would (incorrectly) get:
99 x 11 = 9 (9 + 9) 9 = 9 18 9 = 9189
But that would be incorrect mathematically.
To compensate (or, to present the full rules for the trick), we take the sum of this result as the middle digit, and apply the carry to the next digit to the left, so:
99 x 11 = 9 (9+9) 9 = (9+1) 8 9 = 10 8 9 = 1089
And we now have the correct result.
As another example, let us look at 47 x 11:
47 x 11 = 4 (4+7) 7 = (4+1) 1 7 = 5 1 7 = 517
Got it? Try it with some other examples.
In grade school, when learning to do arithmetic by hand (you still are taught how to do arithmetic by hand, right?), we first learned the concept of sum and carry. This bore value as we were applying this to place values of the number.
Little did you know then, but you were learning the basics of effective numerical and logical problem solving within the domain of Computer Science in grade school!
For example, in the case of the number 18, when dissecting the number into its place values, we have:
In single digit terminology, 18 is expressed as a sum of 8 with a carry of 1. We see this more clearly when producing the value, see the original equation of 9+9:
1 <-- carry (to be added to 10s position) 9 + 9 ---- 8 <-- sum (of 1s position)
See what is happening here? The basis for adding multiple-digit numbers. Perhaps it would make more sense if we showed how adding 9 + 9 was in fact adding two 2-digit numbers together:
1 <-- carry (to be added to 10s position) 09 +09 ---- 8 <-- sum (of 1s position)
Then we have the follow-up addition to determine the value of the 10s place:
1 0 +0 -- 1 <-- sum (of 10s position)
and we would technically have a resulting carry of 0 (but adding zero to any values gives us the value itself– the so-called additive identity property we learned in math class).
Once we are all said and done, we concatenate the tens and ones places together:
1 (ten) and 8 (ones): 18
In this case we merely extend the pattern from double digits, rippling through a series of comparing each set of two consecutive digits.
Let's look at 123 x 11:
123 x 11 = 1 (1 + 2) (2 + 3) 3 = 1 3 5 3 = 1353
And digit-based additions that generate a carry are similarly propagated.
567 x 11:
567 x 11 = 5 (5 + 6) (6 + 7) 7 = (5 + 1) (1 + 1) 3 7 = 6 2 3 7 = 6237
When doing this, we need to evaluate the number from right to left (just as we would do it if we were to compute it purely mathematically by hand):
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.
It is your task to write the program that will use the above method to compute the requested one-, two-, or three-digit value against a multiplicand of 11 (without using any multiplication to obtain your result).
Your program should:
Several operating behaviors are shown as examples.
A two digit value:
lab46:~/src/cprog/mbe0$ ./multby11 Enter value: 32 32 x 11 = 352 lab46:~/src/cprog/mbe0$
Next, a one digit value:
lab46:~/src/cprog/mbe0$ ./multby11 Enter value: 7 7 x 11 = 77 lab46:~/src/cprog/mbe0$
Finally, three digit value:
lab46:~/src/cprog/mbe0$ ./multby11 Enter value: 567 567 x 11 = 6237 lab46:~/src/cprog/mbe0$
The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate.
Be sure to provide any commentary on your opus regarding realizations had and discoveries made during your pursuit of this project.
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ submit cprog mbe0 multby11.c Submitting cprog project "mbe0": -> multby11.c(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.