Question: To write a function that computes the square of a number is simple: multiply the number by itself. In this exercise, we will re -
To write a function that computes the square of a number is simple: multiply the number by itself. In this exercise, we will reimplement the square function and use a different algorithm, one that relies on addition instead of multiplication.
If you want to multiply two numbers together, the most basic approach is to think of it as repeating the process of adding one number to itself. The number of repetitions is where the second number comes into play. For example, if we wanted to multiply three and five, we could think about it as adding three to itself five times. Three plus three is six, plus three is nine, plus three is and finally plus three is Generalizing this, if we want to implement the idea of squaring a number, call it we would add to itself times.
Implement the square function using repeated summing.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
