USING SCHEME Im having difficulty coming up with the way to

USING SCHEME

I\'m having difficulty coming up with the way to create this method. I need to square an inputted number, but without using multiplicaiton. I need to call a previously defined \'add\' function that works correctly by adding two numbers together. I cannot use mutliplication at all in this method called \'Square\'. Thank you for any help.

Solution

if your add methods return the sum of the two numbers it is simple to implement square without using multiplication,

all the thing we need to do is add the number, number times this is what the square is.

lets take a sq variable and i as temporary variable

the method square is as follows

int square(int num)

{

s=num;

for(i=1;i<num;i++)

s=add(s,num);

return s;

}

the above code will add the num to s n times by iterating the loop n-1 times. the above method will return the square of the num.

USING SCHEME I\'m having difficulty coming up with the way to create this method. I need to square an inputted number, but without using multiplicaiton. I need

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site