Advertisement
Sayukoo

[Rekurencja] Fibonacii n-ty wyraz

Nov 5th, 2019
81
0
Never
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. #include <string.h>
  3.  
  4.  
  5. int fibonacci(int n)
  6. {
  7.     if (n<=0)
  8.         return 0;
  9.     else if(n==1)
  10.         return 1;
  11.     else if (n==2)
  12.         return 1;
  13.         else
  14.         return fibonacci(n-1)+fibonacci(n-2);
  15. }
  16. int main()
  17. {
  18.     int n;
  19.     printf("Podaj ilosc liczb ktora chcesz obliczyc w ciagu fibonacciego: ");
  20.     scanf("%d",&n);
  21.     printf("%d wyraz ciagu wynosi %d",n,fibonacci(n));
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement