Calculate power (x^y) but not use power key.and show result (x^y). In C & C++ program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Calculate power (x^y) but not use power key.and show result (x^y). In C & C++ program

Please help me

27th Aug 2019, 4:52 PM
pratima sharma
pratima sharma - avatar
11 Answers
+ 3
Hint: use for/while loop or recursion
27th Aug 2019, 5:07 PM
voja
voja - avatar
+ 1
pratima sharma so you want to calculate x^y, but avoid using a predefined function, like pow()?
27th Aug 2019, 5:00 PM
Stefan Secrieru
Stefan Secrieru - avatar
+ 1
If the answer to my question is yes, than as voja 🏊‍♂️ said try using for loop and continue multiplying the number x with itself until you got the y number of multiplications.
27th Aug 2019, 5:10 PM
Stefan Secrieru
Stefan Secrieru - avatar
+ 1
pratima sharma Show some code to prove you tried.
27th Aug 2019, 5:10 PM
Manual
Manual - avatar
+ 1
pratima sharma Idk if you are , but it will most likely give ERROR on Turbo C++ , Turbo is old
28th Aug 2019, 8:12 AM
Shahil Ahmed
Shahil Ahmed - avatar
0
int y = 5; int x = 2; int x2 = x; for(int i = 0; i < y; i++){ x = x * x2; } cout << x << endl; sorry i dont have the time to check if this is correct but i think it is, im in a hurry so sorry it is wrong :)
27th Aug 2019, 5:08 PM
Cat Sauce
Cat Sauce - avatar
0
Sorry cat sauce your program in run time error
27th Aug 2019, 5:25 PM
pratima sharma
pratima sharma - avatar
0
pratima sharma what what, how is that even possible btw its c++
27th Aug 2019, 5:28 PM
Cat Sauce
Cat Sauce - avatar
0
pratima sharma i check it out myself and it worked just fine, this is the code: c++ #include <iostream> using namespace std; int main() { int y = 5; int x = 2; int x2 = x; for(int i = 0; i < y-1; i++){ x = x * x2; } cout << x << endl; return 0; }
27th Aug 2019, 5:32 PM
Cat Sauce
Cat Sauce - avatar
0
Ok I checked
27th Aug 2019, 5:34 PM
pratima sharma
pratima sharma - avatar
0
pratima sharma did it work?
27th Aug 2019, 8:21 PM
Cat Sauce
Cat Sauce - avatar