moranguinho

ex10ER3

Apr 10th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /*10) Escreva um algoritmo que gere a série de Fibonacci até o termo 'n' que é informado
  2. pelo usuário. A série de Fibonacci é formada pela sequência: 1, 1, 2, 3, 5, 8, 13, 21, 34,
  3. 55, ... , etc.*/
  4. #include <stdio.h>
  5. int main(void)
  6. {
  7. int i, n, ant=1, atual=1, prox;
  8.  
  9. printf("Insira um numero: ");
  10. scanf("%d", &n);
  11.  
  12. printf("1\t1\t");
  13.  
  14. for(i=3;i<=n;i++)
  15. {
  16. prox = atual + ant;
  17. ant = atual;
  18. atual = prox;
  19. printf("%d\t", prox);
  20. }
  21. }
Add Comment
Please, Sign In to add comment