Advertisement
Mahfuz123

1176 - Fibonacci Array

Jun 25th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. long long int n,count,first,second,f;
  6. int num,i;
  7. scanf("%d",&num);
  8.  
  9. for(i=1; i<=num; i++)
  10. {
  11. scanf("%lld",&n);
  12. if(n>=0 && n<=60)
  13. {
  14. first = 0;
  15. second = 1;
  16. count = 0;
  17. while(count<=n)
  18. {
  19. if(count<=1)
  20. {
  21. f = count;
  22. }
  23. else
  24. {
  25. f = first + second;
  26. first = second;
  27. second = f;
  28. }
  29.  
  30. count++;
  31.  
  32. }
  33. printf("Fib(%lld) = %lld\n",n,f);
  34. }
  35. }
  36.  
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement