C语言斐波纳契(Fibonacci)算法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_43669941/article/details/84192220
#include <stdio.h>

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

int main(void) {
	int n;
	scanf("%d", &n);
	printf("%d\n", fib(n));
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43669941/article/details/84192220