递归算法
public int ShuZi(int i)
{
int sum = 0;
if (i <= 0)
{
sum = 0;
}
else if (i == 1 || i == 2)
{
sum = 1;
}
else
{
sum = ShuZi(i-1) + ShuZi(i-2);
}
return sum ;
}
static void Main(string[] args)
{
Program pg = new Program();
Console.Write("请输入数字:");
int shuzi= int.Parse(Console.ReadLine());
int zongshu = pg.ShuZi( shuzi);
Console.Write("第"+shuzi+"个数的数字是:"+zongshu);
Console.ReadLine();
}