Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to write a program that computes the value of a^b(a**b) using repeated multiplication. Without using the operator(**)

I only know how to do it with the **.
Posted
Comments
joshrduncan2012 11-Sep-13 13:15pm    
What have you tried?

1 solution

Here: http://docs.python.org/2/library/math.html[^].

It does not use any operators, just the call. Formally, I answered.

However, the meaning of your question is not clear. Do you mean that you want to implement exponent using other functions as multiplication? For integer exponents of not? Note that "repeated multiplication" is only possible of this is an integer degree.

Is is a homework? Is this is an integer power, I'll just give you the idea: you should avoid doing N multiplications. For example, to calculate N**5, you need to calculate N*N, then multiply the result by itself, then multiply the result by N. This is just the hint. For numeric data, it makes no sense at all, but what to do if, for example, the operand is a matrix? If N is big, multiplying N times is not an option, Then the algorithm based on my hint is the way to go.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900