summary refs log blame commit diff stats
path: root/tinyc/win32/examples/fib.c
blob: 6a4bdf5c4c249a51e60ee81a58caeba957851717 (plain) (tree)























                                                             
#include <stdio.h>
#include <math.h>

int fib(int n)
{
	if (n <= 2)
		return 1;
	else
		return fib(n-1) + fib(n-2);
}

int main(int argc, char **argv) 
{
	int n;
	if (argc < 2) {
		printf("usage: fib n\n"
			   "Compute nth Fibonacci number\n");
		return 1;
	}
		
	n = atoi(argv[1]);
	printf("fib(%d) = %d\n", n, fib(n));
	return 0;
}