ab_tanjir

fibonacci

Sep 28th, 2019
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. int fibo(int);
  3.  
  4. int main()
  5. {
  6.     int num;
  7.     int result;
  8.  
  9.     printf("Enter the nth number in fibonacci series: ");
  10.     scanf("%d", &num);
  11.     if (num < 0)
  12.     {
  13.         printf("Fibonacci of negative number is not possible.\n");
  14.     }
  15.     else
  16.     {
  17.         result = fibo(num);
  18.         printf("The %d number in fibonacci series is %d\n", num, result);
  19.     }
  20.     return 0;
  21. }
  22. int fibo(int num)
  23. {
  24.     if (num == 0)
  25.     {
  26.         return 0;
  27.     }
  28.     else if (num == 1)
  29.     {
  30.         return 1;
  31.     }
  32.     else
  33.     {
  34.         return(fibo(num - 1) + fibo(num - 2));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment