cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
need some help please
need some help please
Mar 10, 2013 at 10:44am UTC
abzksm
(21)
I input X,Y
and x^y where x=x*x*...x (y times)
so how i can find power in C++?
Mar 10, 2013 at 11:12am UTC
abhishekm71
(820)
If y is of type int and y > 0 you can try:
1
2
3
long
power = 1;
for
(
int
i=0;i<y;i++) power *= x;
Or more generally, you can use the built in C++ function "pow". You will have to include math.h. The documentation of this function can be found at
http://www.cplusplus.com/reference/cmath/pow/
Topic archived. No new replies allowed.