C#部分---语言经典题目——兔子生兔子

根据本月成兔=上月成兔+上月小兔;本月小兔=上月幼兔;本月幼兔=本月成兔

利用while循环:

Console.WriteLine("请输入月份:");
//int m = int.Parse(Console.ReadLine());
//int ct = 0;
//int xt = 0;
//int yt = 1;
//int zt = 1;
//int i = 1;
//while(i<=m)
//{
// if (i == 1)
// {
// ct = 0;
// xt = 0;
// yt = 1;
// }
// else
// {
// ct = ct + xt;
// xt = yt;
// yt = ct;
// }

// zt = ct + xt + yt;
// i++;
//}

//Console.WriteLine("第" + m + "个月的成兔对数是:" + ct);
//Console.WriteLine("第" + m + "个月的小兔对数是:" + xt);
//Console.WriteLine("第" + m + "个月的幼兔对数是:" + yt);
//Console.WriteLine("第" + m + "个月的成总兔对数是:" + zt);

 

利用for循环:

// Console.WriteLine("请输入月份:");
// int m=int.Parse(Console.ReadLine());
// int ct = 0;
// int xt = 0;
// int yt = 1;
// int zt=1;
// for (int i = 1; i <= m;i++ )
// {
// if (i == 1)
// {
// ct = 0;
// xt = 0;
// yt = 1;

// }
// else
// {
// ct = ct + xt;
// xt = yt;
// yt = ct;


// }
// zt = ct + xt + yt;
//}
//Console.WriteLine("第" + m + "个月的成兔对数是:" + ct);
//Console.WriteLine("第" + m + "个月的小兔对数是:" + xt);
//Console.WriteLine("第" + m + "个月的幼兔对数是:" + yt);
//Console.WriteLine("第" + m + "个月的成总兔对数是:" + zt);

posted @ 2016-10-10 21:43  88旧港  阅读(180)  评论(0编辑  收藏  举报