Write C program to generate nth fibonacci term using recursion


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to generate nth fibonacci term using recursion


  1.  
  2. #include<stdio.h>
  3.  
  4. int fibonacci(int n)
  5. {
  6. if((n==1)||(n==0))
  7. {
  8. return(n);
  9. }
  10. else
  11. {
  12. return(fibonacci(n-1)+fibonacci(n-2));
  13. }
  14. }
  15.  
  16. int main()
  17. {
  18. int n,i=0;
  19. printf("Input the number of terms for Fibonacci Series:");
  20. scanf("%d",&n);
  21. printf("\nFibonnaci Series is as follows\n");
  22. while(i<n)
  23. {
  24. printf("%d ",fibonacci(i));
  25. i++;
  26. }
  27.  
  28. return 0;
  29. }
  30.  

Result

C language

     





Related Topics




Popular Posts