+ 1

How do i use squaring cubing power of 4 etc.

title sais it all i did try #include <cmath>...z=x^y; but z will be 0

19th Feb 2017, 12:24 AM
Damian
Damian - avatar
3 Answers
+ 5
@Himanshu It doesn't seems logical at all you must first input the values and then call the pow function.
19th Feb 2017, 6:51 AM
Megatron
Megatron - avatar
0
Hi there! if you want to find the value of no. x to the power y,then try the following code :- #include<iostream> #include<cmath> using namespace std; int main(){ int x, y, z; cin>>x; cin>>y; z = pow(x,y); cout<<z; return 0; } Here pow(x,y) is the function of cmath library used for finding the value of x to the power y. Happy coding!
19th Feb 2017, 4:06 AM
Himanshu Kumar
Himanshu Kumar - avatar
0
oops, sorry. Thanks for the correction. It's alright now
19th Feb 2017, 7:26 AM
Himanshu Kumar
Himanshu Kumar - avatar