Next: Compiling the Example Program, Previous: Complete Program Explanation, Up: A Complete Program [Contents][Index]
Here’s the same example, explained line by line. Beginners, do you find this helpful or not? Would you prefer a different layout for the example? Please tell rms@gnu.org.
#include <stdio.h> /* Include declaration of usual */ /* I/O functions such asprintf
. */ /* Most programs need these. */ int /* This function returns anint
. */ fib (int n) /* Its name isfib
; */ /* its argument is calledn
. */ { /* Start of function body. */ /* This stops the recursion from being infinite. */ if (n <= 2) /* Ifn
is 1 or 2, */ return 1; /* makefib
return 1. */ else /* otherwise, add the two previous */ /* Fibonacci numbers. */ return fib (n - 1) + fib (n - 2); } int /* This function returns anint
. */ main (void) /* Start here; ignore arguments. */ { /* Print message with numbers in it. */ printf ("Fibonacci series item %d is %d\n", 20, fib (20)); return 0; /* Terminate program, report success. */ }