Search

Fibonacci series

1 /* 2 * This program is about to find nth fibonacci no 3 * e.g fibonacci series : 0, 1, 1, 2, 3, 5, 8, ......... 4 * 0th fibonaci no. = 0 5 * 1st fibonaci no. = 1 6 * 2nd fibonaci no. = 1 7 * 3rd fibonaci no. = 2 8 * etc. 9 */ 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 14 int fib(int n) 15 { 16 if (n == 0) 17 return 0; 18 if (n == 1) 19 return 1; 20 return fib(n-1) + fib(n-2); 21 } 22 23 int main() 24 { 25 int n; 26 printf("Enter the position :"); 27 scanf("%d",&n); 28 printf("%dth fibonacci number in fibonacci series is %d\n",n, fib(n)); 29 return 0; 30 }

0 views

©2018 by memoryfaults.com. Proudly created with Wix.com