用c++语言,用递归的方法编写函数求Fibonacci级数
时间: 2024-05-12 09:19:30 浏览: 63
源代码_用递归方法编写函数_
```
#include <stdio.h>
int fibonacci(int n)
{
if(n == 0 || n == 1)
return n;
else
return fibonacci(n-1) + fibonacci(n-2);
}
int main()
{
int n;
printf("Please enter the number of terms for Fibonacci series: ");
scanf("%d", &n);
printf("Fibonacci series: ");
for(int i=0; i<n; i++)
printf("%d ", fibonacci(i));
return 0;
}
```
阅读全文