阶乘,阶乘和的算法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            kk ww = new kk();
            Console.WriteLine(ww.dd(3));

            Console.Read();
        }
    }
    //阶乘
    class kk
    {
        public int aa(int i)
        {
            if (i == 1)
                return 1;
            else if (i == 2)
                return 2;
            else if (i == 3)
                return 6;
            else
                return i * aa(i - 1);
        }
        //阶乘和
        public int ccc(int i)
        {
            if (i == 1)
                return 1;
            else if (i == 2)
                return 3;
            else

                return ccc(i - 1) + aa(i);
        }
        // 1 1 2 3 5 8 13
        public int dd(int i)
        {
            if (i == 1)
                return 1;
            if (i == 2)
                return 1;
            else
                return dd(i - 1) + dd(i - 2);
        }
    }
}

posted on 2009-08-12 17:15  小脑斧子  阅读(633)  评论(0编辑  收藏  举报

导航