Last active
August 29, 2015 14:24
-
-
Save kalimalrazif/e72f51d74ac1d9087306 to your computer and use it in GitHub Desktop.
Ejemplo de recursividad, potenciació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
#include <stdio.h> | |
/* Prototipo de la función */ | |
double potencia(int, int); | |
int main(){ | |
// Declaramos las variables | |
int bas = 2; | |
int expo = 3; | |
// Imprimimos el resultado | |
printf("%d elevado a la %d da como resultado %d", bas, expo, potencia(2,3)); | |
// Todo esta bien, retornamos 0 | |
return 0; | |
} | |
double potencia(int base, int exponente){ | |
// Caso base | |
if (exponente == 0 ) return 1; | |
// Recursividad | |
return nro * potencia(base, exponente -1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment