This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog:fall2022:projects:sof0 [2022/09/15 03:38] – [BACKGROUND] rspringe | notes:cprog:fall2022:projects:sof0 [2022/09/15 03:50] (current) – [VERIFICATION] rspringe | ||
---|---|---|---|
Line 4: | Line 4: | ||
This trick works with any multiple of 5 up to three digits (5 to 995), and can be done without much difficult math or a calculator. | This trick works with any multiple of 5 up to three digits (5 to 995), and can be done without much difficult math or a calculator. | ||
+ | |||
+ | Let's take an example number: 105. To calculate the square of 105, we can split the number into two parts, then perform a set of calculations on each part, in order to get our answer. | ||
+ | |||
+ | The two parts we want to split our number into are as follows: | ||
+ | |||
+ | * The " | ||
+ | * The " | ||
+ | |||
+ | Calculating the back portion is easy, we just need to multiply 5 by itself to get its square: | ||
+ | |||
+ | 5 * 5 = 25 | ||
+ | |||
+ | To calculate the front portion, we take our number (10), add one to it, and multiply these two values together to get the front portion of the answer: | ||
+ | |||
+ | 10 * (10 + 1) = ?\\ | ||
+ | 10 * 11 = ?\\ | ||
+ | 10 * 11 = 110 | ||
+ | |||
+ | Finally, we bring the two portions back together to get our answer: | ||
+ | |||
+ | 110 | ||
+ | 11025\\ | ||
+ | 105 * 105 = 11025 | ||
=====SPECIFICATIONS===== | =====SPECIFICATIONS===== | ||
Line 12: | Line 35: | ||
=====VERIFICATION===== | =====VERIFICATION===== | ||
+ | In the project files that you grabbed, there is a reference program, " | ||
+ | |||
+ | This reference program will run a version of sof0 similar to what you will be creating, where you can enter a multiple of 5, and it will output its square. | ||
+ | |||
+ | You can use this reference to check the output of the program you will be writing, along with the format of the output. |