Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/10/2014, 06:18
ecfisa
 
Fecha de Ingreso: julio-2012
Mensajes: 133
Antigüedad: 11 años, 9 meses
Puntos: 22
Respuesta: Algoritmo potencia

Hola.

Mas opciones.

Iterativo:
Código C++:
Ver original
  1. int pow(int b, int e)
  2. {
  3.   int r = 1;
  4.   for(; e; e--) r *= b;
  5.   return r;
  6. }

Recursivo:
Código C++:
Ver original
  1. int pow(int b, int e)
  2. {
  3.   if (e == 0) return 1;
  4.   return b * pow(b, e-1);
  5. }

Saludos.