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 computing the square of any number ending with 5.
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 computing the square of any two-digit number that ends with 5.
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:
Squaring is essentially multiplying a number by itself-
While not outwardly a difficult procedure, the nature of multiplying multiple digit numbers in your head can quickly result in more steps (and more steps means more time, if doing things the traditional way).
Finding a shortcut through this process enables it to remain solidly within the realm of mental math, and makes for a good algorithm to practice implementing on the computer.
This particular trick relies on a subset of the squares: those ending with a 5 (a five in the ones place).
The implementational scope of this trick will be just values of one-, two-, and three-digits ending with 5:
The trick here is two-fold. First, we separate the one's place 5 from the rest of the number (which can be accomplished in our mind's easily enough, but on the computer we must resort to some math).
We then take that isolated five and square it; we'll 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 remaining digits of the original value, 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
For a single digit number like 5, when you take the 5 away, what do you get? ZERO. Zero times anything is zero, so the result is 0 25, or 25 (ie this process still works).
For three digit numbers like 105, we have 10, and its increment is 11, so 10 x 11 = 110.
105 * 105 = 10*(10+1) 5*5 = 10*11 5*5 = 110 25 = 11025
It is your task to write the program that will use the above method to compute the square of the input value ending with a 5 (you are to input the entire number, including the 5 at the end).
Your program should:
lab46:~/src/cprog/squares$ ./squares Enter value: 75 75 x 75 = 5625 lab46:~/src/cprog/squares$
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 mms0 squares.c Submitting cprog project "squares": -> squares.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.