home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
MC20.ZIP
/
FIBO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-20
|
613b
|
36 lines
/*
* Program to calculate a fibonacci number.
*
* This demonstrates a heavily RECURSIVE function.
*
* Copyright 1988,1990 Dave Dunfield
* All rights reserved.
*/
#include \mc\stdio.h
#define MAXFIB 24 /* Largest we can do in 16 bits */
/*
* Recursive function to calculate a fibonacci number
*/
unsigned fibo(num)
unsigned num;
{
if(num <= 2)
return 1;
return fibo(num-1) + fibo(num-2);
}
/*
* Main function to call "fibo" in a loop,
* and display the result.
*/
main()
{
int i;
for(i=1; i <= MAXFIB; ++i)
printf("Fibonacci(%u) = %u\n", i, fibo(i));
}