当前位置:网站首页>Finding the value of the nth term of Fibonacci sequence by recursion

Finding the value of the nth term of Fibonacci sequence by recursion

2022-06-22 23:17:00 Xiaomurong

Find... By recursion Fibonacci Sequence number n Item value . This series has the following characteristics : The first 1 Number and number 2 All of them are 1, From 3 Number of openings , Each number is the sum of its first two numbers .

#include <stdio.h>
unsigned Fib(unsigned n)
{
    
	if(n>2)
		return Fib(n-1)+Fib(n-2);
	else
		return 1;
}
int main(void)
{
    
	unsigned n,ret;
	puts(" Please enter Fibonacci The first n term :");
	scanf("%d",&n);
	ret=Fib(n);
	printf("Fib The first %d Items for :%d\n",n,ret);
	return 0;
}

原网站

版权声明
本文为[Xiaomurong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221502449343.html