26th Jun 2020, 7:57 PM
TeaserCode
13 Answers
+ 5
^ is reserved for bitwise XOR
26th Jun 2020, 8:06 PM
♡Addy♡
♡Addy♡ - avatar
+ 3
Why not use pow function from <math.h>?
26th Jun 2020, 8:08 PM
Igor Kostrikin
Igor Kostrikin - avatar
+ 1
maybe use for loop and multiply itself on each iteration?
26th Jun 2020, 8:34 PM
Bobby Fischer
Bobby Fischer - avatar
+ 1
#include <iostream> using namespace std; int pow(int a, int b) { int base = a; for(int i=1;i<b;i++){ a*=base; } return a; } int main() { int a; int b; cout << "Vnesi stevili za eksponent in osnovo: " << '\n'; cin >> a; cin>>b; cout << "Rezultat = " << pow(a,b); return 0; }
28th Jun 2020, 8:09 PM
Digvijay Gupta✨
Digvijay Gupta✨ - avatar
0
I still do not know what expression is returning in pow() definition.
27th Jun 2020, 4:42 AM
TeaserCode
0
There is no special arithmetic operator.
27th Jun 2020, 7:57 AM
Igor Kostrikin
Igor Kostrikin - avatar
0
#include <iostream> #include <math.h> using namespace std; double power(double a, int b) { return pow(a,(double)b); } int main() { double a = 3.2; int b = 5; cout << "Vnesi stevili za eksponent in osnovo: " << '\n'; cin >> a >> b; power(a,b); cout << "Rezultat = " << pow(a,b); } you can use this way or else use loop for (int i=1;i<=b;i++) a*=b; return a; here a stores power value where a raised to b
27th Jun 2020, 9:48 AM
Nikhil Maroju
Nikhil Maroju - avatar
0
Ye, it works. I know that here is type conversion but I have not how to do that.
27th Jun 2020, 1:26 PM
TeaserCode
27th Jun 2020, 7:42 PM
Igor Chicu
Igor Chicu - avatar
0
Chicu, in your example I think you use pointer, right?
28th Jun 2020, 8:04 AM
TeaserCode
0
Marjan, no he uses recursion, which is not a good implementation because of memory consumption and program optimization.
28th Jun 2020, 2:20 PM
Vasile Eftodii
Vasile Eftodii - avatar
0
Vasile i'm not going to argue with you on memory and optimisation since this is a simple function not a game engine,i'm wondering why you didn't said that it should be done in assembly
28th Jun 2020, 6:30 PM
Igor Chicu
Igor Chicu - avatar