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 two numbers together that are near a common power of 10.
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 two values together that are near a common power of 10.
Mental Math constitutes an intersection of mental techniques and math- instead of utilizing a purely math-only solution, textual 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 numeric manipulation and simple (reduced) multiplication. To wit:
This is one of the sixteen Vedic Math sutras, which (translated) comes out to mean “all from nine, the last from ten”.
Applying this concept can be most immediately visible in the case of subtracting from a power of 10:
100 - 57 9-5=4; 7, being the last, is 10-7=3 ---- 43
Is it really that easy? Let's try a larger example:
10000 - 2678 ------
Again, remember “all from 9”… so the 2, 6, and 7 will be evaluated against 9, and the 8, being the last, will be evaluated against 10.
Then:
We see that:
So our answer is: 7322
The trick is to make sure we have enough digits to match up with the zeroes in the power of 10. If the number we are subtracting is smaller, we simply add leading zeroes (0 + 9 = 9):
1000 1000 - 52 => - 052 ----- ----- 948
Pretty neat, eh?
Multiplication using this principle is also rather straightforward, provided both numbers share a common power of 10 (as such, this is still considered a special case for multiplication– something where you can identify a pattern and apply it to perform the operation in a more optimized fashion than applying the general method).
The procedure is basically as follows:
And what about cases where the numbers are in excess of their common base? Same thing:
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
And how about mixed? One in excess, one short?
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
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:
103 100 - 1 - 18 ==== ==== 102 82 <-- all by nine, last by 10 10282 and voila! Our answer.
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).
Your program should:
lab46:~/src/cprog/nikhilam$ ./nikhilam Enter first number: 91 Enter second number: 99 91 x 99 = 9009 lab46:~/src/cprog/nikhilam$
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 nikhilam nikhilam.c Submitting cprog project "nikhilam": -> nikhilam.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.