Discrete Mathematics question: How to write a step-by-step algorithm for raising a certain number to a certain exponent?
how do you think it please ?
...for example ?
def exponent(number, power) return number**power There you are, algorithm:-)
that seems a bit short @estudier isn't it? i mean the algorithm loops doesn't it?
It's a function, you call it, like exponent(3,6) and it returns 3^6 I am not really sure what you are looking for to be honest. Any program code can be rewritten as an algorithm.
would a javascript code help? lol
really?
and i prefer c @gaara438125
but an algorithm has to be detailed enough for a program to run right @estudier ?
i prefer C++ lol
@lgbasallote A function is a built in type in many programming languages ( bit like math, really) Most higher level programming languages are abstract or "high-level". I mean, in theory, you could write the algorithm in machine language but it would be very long and completely incomprehensible.
hmm fair enough
I can execute that code on my computer just as it is but it does rely on the language framework having already been set up on my computer.
i just couldn't figure out how to initiate my loop....
i thought discrete math algorithm could help....
Oh, I see, your are dropping a level of abstraction....
You want to do it as repeated multiplication or something like that?
yes...something like that
Here is one I just lifted off the web int powerFunc(int x, int y) { for (int i = 0; i < x; i++) { sum *= y; // here it will keep mulitplying itself until // the condition is met } return (sum); } your main would look like this: int result = powerFun(x,y);
This is still relying on a function call to work but has a loop structure...
no idea what that means////
ie the bit about multiplying until a condition is met.....
nevermind the question....i'll just try to think about it
K.
Join our real-time social learning platform and learn together with your friends!