using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class 斐波那契数列 : MonoBehaviour
{
void Start()
{
Debug.Log(fun(1));
Debug.Log(fun(2));
Debug.Log(fun(3));
Debug.Log(fun(4));
Debug.Log(fun(5));
Debug.Log(fun(6));
Debug.Log(fun(7));
Debug.Log(fun(8));
//1, 1, 2, 3, 5, 8, 13, 21,
}
int fun(int count)
{
if (count <= 0)
return 0;
if (count == 1 || count == 2)
return 1;
else
return fun(count - 1) + fun(count - 2);
}
}
#Unity _ 斐波那契数列
于 2021-04-01 18:04:28 首次发布