Skip to content

Instantly share code, notes, and snippets.

@kalimalrazif
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalimalrazif/e72f51d74ac1d9087306 to your computer and use it in GitHub Desktop.
Save kalimalrazif/e72f51d74ac1d9087306 to your computer and use it in GitHub Desktop.
Ejemplo de recursividad, potenciación
#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