Does anyone know of a way to raise a constant to a variable.

Ex. 15 raised to the (xy)

Im kinda new to this so any help would be much appreciated.

Printable View

- 10-21-2002next_to_nothingraising to a power
Does anyone know of a way to raise a constant to a variable.

Ex. 15 raised to the (xy)

Im kinda new to this so any help would be much appreciated. - 10-21-2002NakeerbCode:
`#include <cmath>`

#include <iostream>

int main(){

int xy = 2;

int x = pow(3, 4); //this means 3 to the fourth

int y = pow(15, xy); //15 to the xy

return 0;

}

- 10-22-2002master5001
Within reason, you can also unroll the multiplications.

Code:`int x, y;`

x = pow(15, 3); //this works

y = 15*15*15; //this is faster

- 10-22-2002vasanth
wll if you want to write a function then this is how it works

Code:

power(x,y)

{

double temp=1;

for(int i=0;i<y+1;i++)

{

temp=temp*x;

}

return temp;

}

- 10-22-2002Davros
>y = 15*15*15; //this is faster

Maybe, but what about:

3^25

or

7^2.6 - 10-22-2002ammar
2^3 doesn't work with me!

Maybe I need to overload it.