User Tools

Site Tools


Sidebar

projects

ntr0 (due 20210825)
pct1 (bonus; due 20210819)
wcp1 (due 20210818)
fwf0 (due 20210825)
pct2 (due 20210825)
wcp2 (due 20210825)
sof0 (due 20210901)
pct3 (bonus; due 20210901)
wcp3 (due 20210901)
dow0 (due 20210908)
pct4 (due 20210908)
wcp4 (due 20210908)
cbf0 (due 20210915)
gfo0 (due 20210915)
pct5 (bonus; due 20210915)
wcp5 (due 20210915)
sam0 (due 20210922)
pct6 (due 20210922)
wcp6 (due 20210922)
cnv0 (due 20210929)
pct7 (bonus; due 20210929)
wcp7 (due 20210929)
cnv1 (due 20211006)
pct8 (due 20211006)
wcp8 (due 20211006)
cos0 (due 20211020)
pct9 (bonus; due 20211020)
bwp1 (bonus; due 20211020)
wcp9 (due 20211020)
oop0 (due 20211027)
gfo1 (due 20211027)
pctA (due 20211027)
wcpA (due 20211027)
oop1 (due 20211103)
pctB (bonus; due 20211103)
wcpB (due 20211103)
oop2 (due 20211110)
pctC (due 20211110)
wcpC (due 20211110)
gfo2 (due 20211117)
pctD (bonus; due 20211117)
pctE (bonus; due 20211201)
bwp2 (bonus; due 20211201)
EoCE (due 20211209)
haas:fall2021:cprog:projects:squares

Corning Community College

CSCS1320 C/C++ Programming

~~TOC~~

Project: MENTAL MATH (SQUARES OF 5)

Objective

To implement a programmatic solution (ie simulation) of a real life process- the mental math trick of computing the square of any two-digit number ending with 5.

Prerequisites

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:

  • ability to obtain input from the user

Scope

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.

Background

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 a value

Squaring is essentially multiplying a number by itself-

  • 5 squared (5^2) is 5*5 or 25
  • 8 squared (8^2) is 8*8 or 64

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 of double digit values (and appears to work on some triple digit values): those ending with a 5 (a five in the ones place).

The operational scope of this trick will be just those two-digit values ending with 5:

  • 15
  • 25
  • 35
  • 45
  • 55
  • 65
  • 75
  • 85
  • 95

Squaring double digit values ending with 5

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:

  • 1's increment (1+1) is 2, so 1*2
  • 2's increment (2+1) is 3, so 2*3
  • 3's increment (3+1) is 4, so 3*4
  • 4's increment (4+1) is 5, so 4*5
  • 9's increment (9+1) is 10, so 9*10

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

Program

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:

  • prompt the user for the number (input)
  • perform the task (process)
  • display the final value (output)

Execution

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.

Reflection

Be sure to provide any commentary on your opus regarding realizations had and discoveries made during your pursuit of this project.

  • Does this trick work (or can it be adapted to work) for three digit values ending with 5?
  • How about 4 digits?

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
  • Executed program must display a total of 2 lines, one for input, one for output.
  • Output must be correct, and match the form given in the sample output above.
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must implement solution using the mental math technique described above
  • Code must be commented
    • have a properly filled-out comment banner at the top
    • have at least 20% of your program consist of //-style descriptive comments
  • Output Formatting (including spacing) of program must conform to the provided output (see above).
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

$ submit cprog squares 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.

haas/fall2021/cprog/projects/squares.txt · Last modified: 2014/02/06 17:23 by 127.0.0.1