最佳答案:
public static int Fab(int n)
{
if (n == 1 || n == 2)
{
return 1;
}
else
{
return Fab(n - 1) + Fab(n - 2);
}
}
其他:
i++;
sum = x + y;
x = y;
if (i <= 30)
{
GetNumber(x, sum);
}
return sum;
非递归方法(利用循环):
int x = 1;
int y = 1;
int sum = 0;
for (int i = 3; i <= 30; i++)
{
sum = x + y;
x = y;
y = sum;
}
return sum;