C examples for Function:Recursive Function
Compute the Fibonacci Sequence Using Recursion
#include <stdio.h> int fib(int); int main()// w ww . ja va 2 s . co m { int counter = 24; printf("The first %d Fibonacci numbers are:\n", counter); for (int k = 0; k < counter; k++) { printf("\t%d ", fib(k)); if (((k+1) % 6) == 0) printf("\n"); } return 0; } int fib(int p) { if (p <= 0) return 0; else if (p == 1) return 1; else return fib(p - 1) + fib(p - 2); }