Skip to content

Commit

Permalink
fibonacci recursivo
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeltakano committed Apr 1, 2018
1 parent ee6fa24 commit 7759ef9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fibonacci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
//
int fibonacci(int entrada, int *vetor, int aux){
int saida;
if(entrada == 1){
saida = vetor[aux-1];
return(printf("%d\n",saida));
}
else if(entrada == 2){
saida = vetor[aux];
return(printf("%d\n",saida));
}
else if(entrada > aux){
aux++;
vetor[aux] = vetor[aux-1] + vetor[aux-2];
return(fibonacci(entrada,vetor,aux));
}
saida = vetor[aux-1];
return(printf("%d\n",saida));
}
//
int main(){
int entrada;
int *vetor,aux;
aux = 1;
scanf("%d",&entrada);
vetor = (int*)malloc(entrada*sizeof(int));
vetor[0] = 1;
vetor[1] = 1;
fibonacci(entrada,vetor,aux);
return(EXIT_SUCCESS);
}
Binary file added fibonacci.exe
Binary file not shown.

0 comments on commit 7759ef9

Please sign in to comment.