Advertisement
lButcherl

Vetor 16

Oct 29th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. /*16. Elabore um algoritmo que armazene em um vetor os 20 primeiros termos da sequência de Fibonacci (0 1 1
  2. 2 3 5 8 13 21 ...). Depois apresente o vetor. */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define tam 20
  7.  
  8. main()
  9. {
  10.       int i,a,b,c,ve[tam];
  11.       a = 0;
  12.       b = 1;
  13.       ve[0] = 0;
  14.       ve[1] = 1;
  15.       for (i=2; i < tam; i++)
  16.       {
  17.           c = a + b;
  18.           ve[i] = c;
  19.           a = b;
  20.           b = c;
  21.           }
  22.           for (i = 0; i < tam; i++)
  23.           {
  24.               printf("%i\n",ve[i]);
  25.               }
  26.               system("pause");
  27.               }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement