用递归算法求斐波那契数列的第N项值

#include <stdio.h>
long fun(int  g)
{
	switch(g)
	{
	case 0:
		return 0;
	case 1:
		return 0;
	case 2:
		return 1;
	}
	return (fun(g-1) + fun(g-2));
}
main()
{
	long  fib;
	int  n;
	printf("Input n:  ");
	scanf("%d", &n);
	printf("n=%d\n", n);
	fib = fun(n);
	printf("fib = %d\n\n", fib);
}

    原文作者:递归算法
    原文地址: https://blog.csdn.net/liuhenghui5201/article/details/7482793
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞