C#递归思路

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:57:35
有一题,牛生牛的问题,
假设牛都是母牛;
说是:
有一个农场有一头成年母牛,每三个月后一头小牛,小牛一年后长大,长大后每三个月又可以生一头小牛,如些循环,问10年后农场一共有多少牛?
开发语言用C#.完全代码 + 详细注释;做到C#规范.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
public class 牛
{
public int 月份;//当月份>12且能整除3时,生一头小牛
public string 出生日期;
}

class Program
{
static void Main(string[] args)
{
牛 a = new 牛();
a.月份 = 12;
a.出生日期 = "牛祖先";
ArrayList arr = new ArrayList();
arr.Add(a);
//开始循环,以月为单位循环
for (int i = 1; i <= 12 * 10; i++)
{
//每个牛的年龄+1
for (int j = 0; j < arr.Count; j++)
{
牛 temp = (牛)arr[j];
temp.月份++;
if (temp.月份 >= 12 && temp.月份 % 3 == 0)
{