Created
June 7, 2013 00:11
-
-
Save briandiaz/5726130 to your computer and use it in GitHub Desktop.
Rápida Exponenciación
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Entidad: Pontificia Universidad Católica Madre y Maestra | |
* Autor: Brian Díaz | |
* Fecha: 28/05/2013 | |
*/ | |
#include <iostream> | |
using namespace std; | |
int RapidaExponenciacion(int x, int n) | |
{ | |
if(n==0) | |
return 1; | |
if(n==1) | |
return x; | |
int b = RapidaExponenciacion(x,n/2); | |
b *= b; | |
if(n%2==1) | |
b*=x; | |
return b; | |
} | |
int main() | |
{ | |
int x = 2, n = 8; | |
cout << RapidaExponenciacion(x,n) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment