C#递归复习

static void Main(string[] args)
{
  Console.WriteLine("请输入你要的数字:");
  long flag = Convert.ToInt64(Console.ReadLine());
  long result = MakeRusult(flag);
  Console.WriteLine("结果是:{0}", Convert.ToString(result));
  Console.ReadKey();
}

static long MakeRusult(long number)
{
  if (number == 1 || number == 2)
  {
    return 1;
  }
  else
  {
    return MakeRusult(number - 1) + MakeRusult(number - 2);
  }
}

posted @ 2019-01-10 21:22 初晨~ 阅读(...) 评论(...) 编辑 收藏