Advertisement

how do u take a number to the power of

Started by February 16, 2002 05:32 PM
15 comments, last by dragonsimoto 22 years, 8 months ago
equal = (num1^num2); i get zero for the answer when i do this with any number combos why dont it work? what is the correct way to do powers of? thanks, dragon
Try pow(num1, num2). Make sure to include math.h.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
oh yeaah, thanks! that is it lol i forgot i remember reading that in a tutorial somewhere any way thanks.
now when i take the pow of some rather large powers, it gives me the same number but smaller pows work perfect. if u know this one let me know if not no big deal.
perhaps the resulting big-ass number doesn''t fit in your data type? i think pow() returns a double, but are you putting it in an int or something?
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
i used int for num1 num2 and equal
so i should use double now for equal right?
Advertisement
ok that worked great now it says e+ some variable which is what i wanted. thanks again.
you could always do a while loop, or even better, bitwise operators if your just doing a square, or square root
-Scott
You could create your own function for a little coding practice...
Example:
float ComputeExponent(float base, float exponent){   int index;   float endresult = base;   for(index = 0; index < exponent - 1; index++)       endresult *= base;   return endresult;} 

Cheers,
-Jesse

| The Hitchhiker''''s Guide to Programming |
"That is not dead which can eternal lie,
And with strange aeons even death may die."
-H.P. Lovecraft
| The Hitchhiker''s Guide to Programming |"That is not dead which can eternal lie,And with strange aeons even death may die."-H.P. Lovecraft
thanks alot u guys u all are great help

This topic is closed to new replies.

Advertisement