/* File: fib1.c
* Author: Richard Chang
* Date: < 12/3/97
* Modified by Sue Evans - 10/30/03
* Section: 101
* EMail: bogar@cs.umbc.edu
*
* A recursive function for fibonacci with tracing.
*/
#include
int Fib(int) ;
int main()
{
int n = -1;
while (n < 1)
{
printf("Enter a positive integer: ") ;
scanf("%d",&n);
}
Fib(n) ;
return 0;
}
/***********************************
* Fib recursively traces the fibonacci sequence
* for the nth number in the sequence
* Input: the number-place in the sequence to find
* Output: the value of the nth number in the sequence
* Side effect: prints tracing for finding the number
***********************************/
int Fib (int n)
{
int result;
printf("> Fib(%d)\n", n);
if (n < 2)
{
result = 1;
}
else
{
result = Fib(n - 1) + Fib(n - 2);
}
printf("< %d\n", result);
return (result);
}