Advertisement
tonygms3

Question 9 Assignment

Dec 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,n;
  5.     printf("Enter sequence\n");
  6.     scanf("%d",&n);
  7.     for(i=1;i<=n;i++)
  8.     {
  9.         printf("%d\n",fibonacci(i));
  10.     }
  11.  
  12.  
  13.  
  14.  
  15.     return 0;
  16. }
  17.  
  18.  
  19.     int fibonacci(int n)
  20.     {
  21.         if(n==0)
  22.         {
  23.             return 0;
  24.         }
  25.         else if(n==1)
  26.         {
  27.             return 1;
  28.         }
  29.         else
  30.         {
  31.             return fibonacci(n-1)+fibonacci(n-2);
  32.         }
  33.  
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement