1 1 2 3 5 8 13 21 ....第30位数是多少

 

 protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(GetNum(1, 1));
    }

    int num = 3;

    public int GetNum(int i, int j)
    {
        int retNum = i + j;
        if (num <= 30)
        {
            num++;
            retNum = GetNum(j, retNum);
        }
        return retNum;
    }

 

 

能用foreach遍历访问的对象必须是集合或数组对象,而这些都是靠实现超级接口IEnumerator或被声明 GetEnumerator 方法的类型。

posted @ 2010-07-06 17:07  会飞的剑  阅读(482)  评论(0)    收藏  举报