/*
递归法求斐波那锲数列
*/
#include<stdio.h>
unsigned long Fibonacci(int n);
int main()
{
int n;
unsigned long temp;
printf("Enter the number of Fibonacci (q to quit):");
while (scanf_s("%d", &n) == 1)
{
for (int i = 1; i <= n; i++)
{
temp = Fibonacci(i);
printf("%lu ", temp);
}
printf("\n");
printf("Enter the number of Fibonacci (q to quit):");
}
return 0;
}
unsigned long Fibonacci(int n)
{
unsigned long f1, f2, f3;
f1 = 1;
f2 = 1;
if (n == 1 || n == 2)
{
return f1;
}
else
{
f2 = Fibonacci(n - 1) + Fibonacci(n - 2);
return f2;
}
}
递归法求斐波那锲数列
最新推荐文章于 2024-08-15 05:02:54 发布