projects
- intro (due 20140124)
- "Hello, World!" (due 20140131)
- data types (due 20140207)
- Squares (due 20140214)
- Day of Week (due 20140221)
- Nikhilam (due 20140228)
- Multiply by 11 (due 20140307)
- Vertically and Crosswise (due 20140321)
projects
This is an old revision of the document!
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 trick here is two-fold.
One, we square the 5 to get 25. That is how our result will end (so bam! we now have our tens and ones place already solved)
Next, we take the value in the tens place, and multiply it by its increment:
We take this result and append the 25 after it.
For example:
15 * 15 = 1*(1+1) 5*5 = 1*2 5*5 = 2 25 = 225
and:
75 * 75 = 7*(7+1) 5*5 = 7*8 5*5 = 56 25 = 5625
It is your task to write the program that will use the above method to compute the square of the requested value ending with a 5.
Your program should:
lab46:~/src/cprog/nikhilam$ ./nikhilam Enter value: 34 34 x 34 = 5625 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.