用c++语言,用递归的方法编写函数求Fibonacci级数
时间: 2024-05-12 22:19:30 浏览: 61
用C++求Fibonacci级数
```
#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;
}
```
阅读全文