Hogy-Bear

Q3

Feb 8th, 2018
252
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int fibonacci(int n);
  4.  
  5. int NthFibNum(int n);
  6.  
  7. int main(int argc, char const *argv[]) {
  8.  
  9.   for(int i = 0; i < 24; i++) {
  10.     fibonacci(i);
  11.     printf("\n");
  12.   }
  13.  
  14.   return 0;
  15. }
  16.  
  17. int NthFibNum(int n) {
  18.   if (n == 0 || n == 1) {
  19.     return n;
  20.    }
  21.    return NthFibNum(n - 1) + NthFibNum(n - 2);
  22. }
  23.  
  24. int fibonacci(int n){
  25.   for (int i = 0; i < n; i ++){
  26.     printf("%d ", NthFibNum(i));
  27.   }
  28.  
  29.   return 0;
  30. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment