Kimossab

Inverter e Fibonnaci um Vector

Jan 7th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. int Fib(int N)
  5. {
  6.         if(N == 0 || N == 1)
  7.                 return N;
  8.         else return Fib(N-1)+Fib(N-2);
  9. }
  10.  
  11. int *InvFib(int vect[], int tam)
  12. {
  13.     int *v = (int *)malloc(sizeof(int) * tam);
  14.     for(int i=0; i<tam; i++)
  15.         v[tam-i-1] = Fib(vect[i]);
  16.     return v;
  17. }
  18.  
  19. void main()
  20. {
  21.     int n;
  22.     printf("Introduza o  tamanho do vetor: ");
  23.     scanf("%d", &n);
  24.     int *vect = (int *)malloc(sizeof(int) * n);
  25.     for(int i=0; i<n; i++)
  26.     {
  27.         printf("Introduza o valor do vetor na posição %d: ", i);
  28.         scanf("%d", &vect[i]);
  29.     }
  30.     int *v = InvFib(vect, n);
  31.     printf("\nVector Fibonnaci Invertido :");
  32.     for(int i=0; i<n; i++)
  33.         printf("[%d]", v[i]);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment