SoFunction
Updated on 2025-03-06

Use recursive algorithm to find the value of the 30th digit


class Program
    {
        static void Main(string[] args)
        {
//Find rules:
            //1,1,2,3,5,8,13,21,34,55,......
            int num = 30;
            (GetNum(30));
            ();
        }
        /// <summary>
/// Find the value of the 30th digit
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        private static int GetNum(int i)
        {
            if (i<=0)
            {
                return 0;
            }else if (i>0 && i<=2)
            {
                return 1;
            }
            else
            {
                return GetNum(i - 1) + GetNum(i - 2);
            }
        }

    }