Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int ElevarRecursivo(float x, int n) {
- if(n < 0) {
- return 1; // ElevarRecursivo(x, -n);
- } else if(n == 0) {
- return 1;
- } else {
- if(n == 1) { // Caso base
- return x;
- } else { // Case recursivo
- int aux = ElevarRecursivo(x, n / 2);
- if(n % 2 == 0) { // n es par
- return aux * aux;
- } else { // n es impar
- return aux * aux * x;
- }
- }
- }
- }
- int main(int argc, char** argv) {
- int s=ElevarRecursivo(2,3);
- printf("%d",s);
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment